请问这条SQL语句 怎么写

来源:百度知道 编辑:UC知道 时间:2024/06/30 18:42:28
8. 下面是部门表DEPT和员工表EMP,写一条SQL语句,找出部门的工资总额超过8000元的部门编号及部门名称:
DEPT:
DEPTNO(部门编号) DNAME(部门名称) LOC(部门所在地点)
10 Accouting BeiJing
20 Reserch TianJin
30 Sales ShangHai
40 Operations ChongQing
EMP:
EMPNO(员工编号) ENAME(员工姓名) AGE(年龄) SALARY(工资) DEPTNO(部门编号) JOB(工作)
0715 SuWei 26 1500 40 Clerk
0864 LuMing 39 3800 30 Analyst
0762 ZouPing 56 3500 10 Manager
0573 Zhaohua 45 2000 30 Sales
0665 ZhuJing 34 2000 10 Clerk
0586 LinJin 50 4000 20 Analyst
0744 ChenQi 38 3800 40 Manger
0749 JinWei 28 2200 20 Clerk
0891 HuMing 26 1700 10 Clerk
0924 LeiFan 40 2500 30 Sales
0783 WeiDong 27 2000 20 Secretary

select DEPTNO,DNAME from DEPT
where DEPTNO in(select DEPTNO from EMP group by DEPTNO having sum(SALARY)>8000)

SQL2005经过测试
select
a.deptno,a.dname,c.salary as 'salary'
from dept
inner join
(select
deptno ,sum(salary) as 'salary'
from emp
group by deptno)c
on a.deptno=c.deptno
where c.salary>8000

select DEPT.DEPTNO, DNAME,sum(SALARY) s
from DEPT ,EMP
where DEPT.DEPTNO = EMP.DEPTNO
group by DEPT.DEPTNO, DNAME
having s > 8000

select SALARY(工资),DNAME(部门名称)from EMP where SALARY(工资)>8000 join DEPT on EMP.DEPTNO =DEPT.DEPTNO