2, 有三张表:(15*2)
Employee 职工 (工号,姓名,性别,年龄,部门)(no,name,sex,age,department)
Wage工资 (工号,工资金额)(no,amount)
Attend出勤 (工号,日期,是否出勤)(no,date,attendance)
对以下2个问题写出SQL语句:
1) 查询工资金额大于8000且2010年缺勤次数小于5次的职工工号和姓名。
2) 统计2010年12月与2010年1月的对比情况,包括员工的工资平均数,出勤率平均数。
sql的复杂查询问题:
答案:2 悬赏:80 手机版
解决时间 2021-12-21 03:53
- 提问者网友:城市野鹿
- 2021-12-20 17:13
最佳答案
- 五星知识达人网友:山有枢
- 2021-12-20 17:43
no,date,attendance
12 2010-10-10 Y
13 2010-11-12 N
1)
思路:先查工资大于8000,再并列查询,小于5次
2010年小于5次的
select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5
故,综上得出结论
select E.no,E.name from Employee E left join Wage W on E.no=W.no left join (select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5)A on E.no=A.no where W.amount > 8000;
2)
思路:先查工资平均数,分别查不同的日期即可
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201212' group by A.no
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201201' group by A.no
12 2010-10-10 Y
13 2010-11-12 N
1)
思路:先查工资大于8000,再并列查询,小于5次
2010年小于5次的
select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5
故,综上得出结论
select E.no,E.name from Employee E left join Wage W on E.no=W.no left join (select A.no count(A.no) from Attend A where attendance group by substring(date,0,4) having count(A.no)<5)A on E.no=A.no where W.amount > 8000;
2)
思路:先查工资平均数,分别查不同的日期即可
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201212' group by A.no
select W.amount/sum(W.amoun),A.no,A.attendance/sum(A.attendance) from Attend A left join Wage W on W.no=A.no where substring(date,0,6)='201201' group by A.no
全部回答
- 1楼网友:掌灯师
- 2021-12-20 18:07
这个你写个sql语句存下来不就行了吗?
select * from abc where name ='' or name ='' or ....
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯