简体   繁体   English

我不知道这个查询

[英]I can't figure out this query

I am a beginner at SQL. 我是SQL的初学者。 I am trying to write a query which "provides the Total salary drawn by all people for each department if the total salary is greater than 300,000". 我正在尝试编写一个查询,“如果总工资大于300,000,则提供每个部门的所有人的总工资”。 I have written some of it, but can't figure it out completely. 我已经写了一些,但不能完全弄清楚。

USE EMP_DB_01;
SELECT DEPTNAME, SUM(SALARY) AS 'Total Salary'
FROM DEPT, EMP 
WHERE (SALARY > 300000) AND (DEPT.DEPTNO = EMP.DEPTNO)
GROUP BY DEPTNAME

Table is here enter image description here 表格在这里输入图片说明

You should use a join between the DEPT and EMP could be based on DEPT.DEPTNO = EMP.DEPTNO ..and for total salary is greater than 300,000 you should use having and not where 您应该在DEPT和EMP之间使用联接,该联接可以基于DEPT.DEPTNO = EMP.DEPTNO ..并且对于总薪水大于300,000的情况,应使用“有”而不是“何处”

Having filter the result of aggregated result .. where filter the rows values 已筛选汇总结果的结果..其中筛选了行值

this return the dept and the the related Total Salary when the sum is > 300.00 当总和> 300.00时,将返回部门和相关的总薪水

USE EMP_DB_01;
SELECT DEPTNAME, SUM(SALARY) AS 'Total Salary'
FROM DEPT
INNER JOIN  EMP ON DEPT.DEPTNO = EMP.DEPTNO
HAVING  SUM(SALARY) > 300000
GROUP BY DEPTNAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM