Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
查找工资低于每种工作的平均工资的员工的姓名给定的解决方案是:
SELECT ENAME,JOB,SAL FROM EMP WHERE SAL<ALL (SELECT AVG(SAL) FROM EMP GROUP BY JOB);
子句中指定的所有列都SELECT必须存在于GROUP BY子句中,但这里不是。内部查询的SELECT子句不包含作业,尽管它在 GROUP BY 子句中指定。
SELECT
GROUP BY
如果我理解正确,您需要列出所有员工的SALary 低于每个员工的所有薪水的平均值JOB。
SAL
JOB
SELECT a.* FROM EMP a INNER JOIN ( SELECT JOB, AVG(SAL) avg_sal FROM EMP GROUP BY JOB ) b ON a.JOB = b.JOB WHERE a.SAL < b.avg_sal