Re: query
Posted in 1999
Topics: General Discussion
Many thanks to all who already came up with an answer but what I need is just ONE answer, not a sorted list. Regards. Henk J. Sanders wrote: > Hi folks. > > Probably a very simple query but I cann't get the point. > > One tabel contains: > - department_code > - manager_code > > A manager can have MORE departments. > > The other table contains: > - employee_nr > - department_code > > Question: > > which manager controls the least nr. of employee's?. > > Any idea. > > Many thanks.
You may only want one answer, but there may be more than one answer. UNLESS
either:
a) every department is GUARANTEED to have a different number of employees
or
b) every manager is GUARANTEED to have a different number of employees
or
c) you are willing to add a rule that provides for selecting between
managers in case of a tie.
I believe the following will list only those managers who have the fewest
number of employees:
a) create view x (manager_code, employees) as:
select manager_code, count(employee_nr) from table a,b wherea.department_code = b.department_code
group by manager_code.
b) select manager_code from x where employees = (select min(employees) from
x)
of course, you can also do this without a view, but the SQL could be
horrendous to read.
Doug Agnew
dagnew@charlottepipe.com
Henk J. Sanders wrote in message <7hehj4$5f9$1@news.xmission.com>...
>
>Many thanks to all who already came up with an answer but what I need is
>just ONE answer, not a sorted list.
>
>Regards.
>
>
>
>Henk J. Sanders wrote:
>
>> Hi folks.
>>
>> Probably a very simple query but I cann't get the point.
>>
>> One tabel contains:
>> - department_code
>> - manager_code
>>
>> A manager can have MORE departments.
>>
>> The other table contains:
>> - employee_nr
>> - department_code
>>
>> Question:
>>
>> which manager controls the least nr. of employee's?.
>>
>> Any idea.
>>
>> Many thanks.
>
>
>