Re: How to do this Query
Posted in 1997
Douglas Wilson — — source: Informix-list mailing list archive (1991-1998)
S.Sathish wrote: > 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 Do you need a strictly SQL solution? If so, the answer is real long, messy, inefficient, and doesn't work for a general 'Nth' number. If at all possible, use 4gl, order by # of employees (in reverse order), and fetch that # of rows. I've posted the ugly SQL here before, so you can find it in dejanews if you like. Cheers, Douglas Wilson