求助求助,一条SQL统计 考勤情况,下面的当天缺勤次数,统计不出来 qin_record 考勤记录表
ID 用户ID 时间段 考勤时间 当前日期
id userid timeslotid time curdate
一条SQL统计 考勤情况,下面的当天缺勤次数,统计不出来
select u.username, r.curdate
,(select time from qin_record where timeslotid=1 and curdate=r.curdate limit 1) as 上午上班
,(select time from qin_record where timeslotid=2 and curdate=r.curdate limit 1) as 上午下班
,(select time from qin_record where timeslotid=3 and curdate=r.curdate limit 1) as 下午上班
,(select time from qin_record where timeslotid=4 and curdate=r.curdate limit 1) as 下午下班
,(select time from qin_record where timeslotid=5 and curdate=r.curdate and 上午上班=null limit 1) as 上午迟到
,(select time from qin_record where timeslotid=6 and curdate=r.curdate and 下午上班=null limit 1) as 下午迟到
,(select time from qin_record where timeslotid=7 and curdate=r.curdate and 上午下班=null limit 1) as 上午早退
,(select time from qin_record where timeslotid=8 and curdate=r.curdate and 下午下班=null limit 1) as 下午早退
,(
(select count(*) from qin_record where curdate=r.curdate and 上午上班=null and 上午迟到=null)
+
(select count(*) from qin_record where curdate=r.curdate and 下午上班=null and 下午迟到=null)
) as 当天缺勤次数
from qin_record r,ums_user u
where r.userid=u.id
group by u.username, r.curdate
order by r.curdate desc ------解决方案-------------------- 晕,
select t1.*,
((select count(*)
from qin_record
where curdate = r.curdate
and 上午上班 = null
and 上午迟到 = null) +
(select count(*)
from qin_record
where curdate = r.curdate
and 下午上班 = null
and 下午迟到 = null)) 当天缺勤次数
from (select t.*,
(select time
from qin_record
where timeslotid = 5
&nbs