Re: How to do this Query
Posted in 1997
Try this:
SELECT dept_id, COUNT(emp_id) FROM Dept, Emp
WHERE Dept.dept_id = Emp.dept_id
GROUP BY 1
ORDER BY 2 DESC
Obviously, the field and table names aren't necessarily correct. Make sure
you GROUP BY each non-summary field.
Hope that helps.
}
}Hi,
}Table : Dept_id Emp_id
}
} I want the dept_id which has Nth maximum number of employees.
}
}Eg: 1st maximum no of employees ie,..,the dept_id which has the max no
} of employees.
} 2nd max no of employees ie,..,the dept_id which is second in the
} list of no of employees in a dept
}
} ..........
}
} So, i want a general method for the Nth case.
}
}***************************************************************************
***
}S.Sathish
}email :ssathish@cmcbang.ernet.in
}***************************************************************************
***
}
}