找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
1. 列出每个部门的平均收入及部门名称;
Select avg(incoming),dept_name from emp,dept where dept2=dept1 group by dept_name;file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AC1.tmp.jpg
2. 财务部门的收入总和;
select sum(incoming) from emp,dept where dept2=dept1  and dept1=101 group by dept_name ;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AC2.tmp.jpg
3. It技术部入职员工的员工号
select sid from emp,dept where dept2=dept1 and dept1=103;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AC3.tmp.jpg
4. 财务部门收入超过2000元的员工姓名
select name from emp ,dept where dept2=dept1  and(incoming >2000) and dept1=101;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD4.tmp.jpg
5. 找出销售部收入最低的员工的入职时间;  
select worktime_start from emp,dept where dept2=dept1  and(select min(incoming)from emp where dept1=102 ) order by incoming asc limit 1;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD5.tmp.jpg
6. 找出年龄小于平均年龄的员工的姓名,ID和部门名称
select name,sid,dept_name from emp,dept where dept2=dept1  and age<(select avg(age)from emp);
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD6.tmp.jpg
7. 列出每个部门收入总和高于9000的部门名称
select sum(incoming)a,dept_name from emp,dept where dept1=dept2 group by dept_name having   a>9000;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD7.tmp.jpg
8. 查出财务部门工资少于3800元的员工姓名
select name from emp,dept where dept2=dept1 and (incoming <3800) and dept1=101;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD8.tmp.jpg
9. 求财务部门最低工资的员工姓名;
select name from emp,dept where dept2=dept1 and(select min(incoming) from emp where dept1=101) order by incoming asc limit 1;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AD9.tmp.jpg
10. 找出销售部门中年纪最大的员工的姓名  
select name from emp,dept where dept2=dept1 and(select max(age)from emp where dept1=102) order by age desc limit 1;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6ADA.tmp.jpg
11. 求收入最低的员工姓名及所属部门名称:
select name,dept_name from emp,dept where dept2=dept1 and (select min(incoming) from  emp) order by incoming asc limit 1;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6ADB.tmp.jpg
12.求李四的收入及部门名称
select incoming,dept_name from emp,dept where dept1=dept2 and name='lisi';
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6ADC.tmp.jpg
13.求员工收入小于4000元的员工部门编号及其部门名称;
select dept1,dept_name from emp,dept where dept1=dept2 and (incoming <4000);
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6ADD.tmp.jpg
14.列出每个部门中收入最高的员工姓名,部门名称,收入,并按照收入降序;
select name,dept_name,incoming,max(incoming) from emp,dept where dept1=dept2 and (select max(incoming) from emp group by dept_name ) group by dept_name order by incoming desc;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AED.tmp.jpg
15.求出财务部门收益最高的俩位员工的姓名,工号,收益
select name,sid,incoming from emp,dept where dept1=dept2 and (select  max(incoming) from emp where dept_name='chaiwu') order by incoming desc limit 2;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AEE.tmp.jpg
16. 查询财务部低于平均收入的员工号与员工姓名:
select sid,name from emp,dept where dept1=dept2 and dept_name='chaiwu' and incoming<(select avg(incoming)from emp dept where dept1=dept2 and dept_name='chaiwu');
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AEF.tmp.jpg
17. 列出部门员工数大于1个的部门名称;   
select count(*)a,dept_name from emp,dept where dept1=dept2 group by dept_name having a>1;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF0.tmp.jpg
18. 列出部门员工收入不超过7500,且大于3000的员工年纪及部门编号;
select age,dept1 from emp,dept where dept1=dept2 and  incoming <=7500 and incoming>3000;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF1.tmp.jpg
19. 求入职于20世纪70年代的员工所属部门名称;
select dept_name from emp,dept where dept1=dept2 and worktime_start like'197%';
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF2.tmp.jpg
20. 查找张三所在的部门名称;
select dept_name from emp,dept where dept1=dept2 and name='zhangsan';
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF3.tmp.jpg
21. 列出每一个部门中年纪最大的员工姓名,部门名称;
select name,dept_name from emp,dept where dept1=dept2 group by  dept_name order by age desc ;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF4.tmp.jpg
22. 列出每一个部门的员工总收入及部门名称;
select sum(incoming),dept_name from emp,dept where dept1=dept2 group by dept_name;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6AF5.tmp.jpg
23. 列出部门员工收入大于7000的员工号,部门名称;
select sid,dept_name from emp,dept where dept1=dept2 and incoming>7000;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B06.tmp.jpg
24. 找出哪个部门还没有员工入职;
select dept_name from dept left join empon dept1=dept2 where name is null;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B07.tmp.jpg
25. 先按部门号大小排序,再依据入职时间由早到晚排序员工信息表
select * from (select * from emp,dept where dept1=dept2 order by dept1 desc)a order by worktime_start asc;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B08.tmp.jpg
26. 找出销售部门收入大于7500,显示他们的SID和姓名和年纪;
select sid,name,age from emp,dept where dept1=dept2 and incoming >7500 and dept_name='xiaoshou';
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B09.tmp.jpg
27. 找出入职于80年代的人,且显示他们的姓名和入职时间,按照先后循序进行排序展示
select name,worktime_start from emp,dept where dept1=dept2 and worktime_start like'198%' order by worktime_start asc;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B0A.tmp.jpg
28. 找出财务部门大于平均收入的人的姓名和收入
select name,incoming from emp,dept where dept1=dept2 and dept_name='chaiwu' and incoming>(select avg(incoming)from emp,dept where dept1=dept2 and dept_name='chaiwu');
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B0B.tmp.jpg
29. 查找收入大于4000元以上的人的姓名和收入
select name,incoming from emp,dept where dept1=dept2 and incoming >4000;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B0C.tmp.jpg
30. 统计各个部门的收入总和并按照从大到小方式排序进行显示
Select sum(incoming) from emp,dept where dept1=dept2 group by dept_name order by incoming desc;
file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps6B0D.tmp.jpg

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册