I am trying to write a query to display manager no. and the lowestwages employee for manager. we discard wages less than 1k So I tried writing a code for it but its giving me an error. I think I have to edit the FROM condition in the second line:
SELECT empno, sal
FROM emp a, emp b
WHERE 开发者_Go百科empno IN (SELECT boss.empno
FROM emp a, emp boss
WHERE a.super = boss.empno)
AND MIN(sal) >1000;
Try this:
SELECT m.empno, min(e.sal)
FROM emp e, emp m
WHERE e.super = m.empno
GROUP BY m.empno
HAVING min(e.sal) > 1000
Basically doing a SELF JOIN on employee table and GROUPing BY manager and getting the MIN salary of employee.
Haven't tested it yet so it may need a bit of tweeking
精彩评论