根据以下表及查询要求,写出SQL查询语句?
1.显示5号部门所有员工的基本信息
select * from emp where deptno=5
2.列出所有办事员(CLERK)的姓名和部门名称
select a.ename,b.dname
from emp a inner join dept b on a.deptno=b.deptno
where a.job='CLERK'
3.列出既不是经理(MANAGER)又不是办事员
但薪金超过5000元的所有员工名单
select name from emp where sal>5000 and job!='MANAGER' and job!='CLERK'
4.查找所有不姓李的明皮员工,显示其姓名及所在部门名称
select a.ename,b.dname
from emp a inner join dept b on a.deptno=b.deptno
where a.ename not like '李%'
5.显示工作时间满3年的员工的姓名和受雇年数
select ename,datediff(year,hiredate,getdate()) as hireyear
from emp where datediff(year,hiredate,getdate())>=3
6.显示所有员工详细资料,按姓名排序
select a.*,b.dname from emp a inner join dept b on a.deptno=b.deptno
order by a.ename
7.查找哪些员工所在的部门规模超过了10人,请显示员工名单
select a.ename from emp a inner join dept b on a.deptno=b.deptno
where b.num>10
8.统计员工人数不少于5人清槐并的部门中所有员工的薪金总额,
显示部门名称答迹及总金额,并将结果按总金额降序排列。
select b.dname,sum(a.sal) as total from emp a inner join dept b on a.deptno=b.deptno
where b.num>=5 group by b.dname order by sum(a.sal) desc
2024-09-04 广告