zzzz 幼苗
共回答了16个问题采纳率:93.8% 举报
1年前 追问
我现在非常担心,即使我写出了完整的SQL,你如果看不太懂SQL的话,那么也是运行不了的。
这样吧,我把核心思路和你说下吧,有什么问题再后续讨论。
因为,你的需求比较复杂,我是用存储过程来实现,在这个存储过程里面,有临时表和游标技术。
下面说下步骤:
假设数据库原始数据为:
姓名打卡时间
张三2013-09-09 09:01:00
李四2013-09-09 08:50:00
王五2013-09-09 18:51:00
赵六2013-09-09 16:30:00
step1:整理,得出每个人的上班时间和下班时间,放在临时表tempBeginEnd里,存储过程接受一个参数日期,记为@queryDate
select name,max(swipingTime) as 'endTime' ,min(swipingTime) as 'beginTime' into tempBeginEnd from t_records group by name where swipingTime=@queryDate
step2:再对临时表tempBeginEnd进行处理,
SQL语句如下:
select case when beginTime<09:00:00 then '正常上班'
when beginTime>09:00:00 and beginTime<10:00:00 then '迟到'
when beginTime>10:00:00 then '旷工' end
as '上班考勤',
case when endTime<18:00:00 then '早退' end as '下班考勤'
into temp
from tempBeginEnd
step3:但是现在的temp表目前还不能满足需求,要考虑加班
此时要用到游标去遍历,去查询次日早上在9:00之前的刷卡次数是否大于2次,
如果大于2次,则将早退更新成加班
select @folloingCount=count(*) from temp where swipingTime=次日 and swipingTime<10:00:00
if @followingCount>=2 update temp set 下班考勤='加班'
1年前1个回答
1年前1个回答
1年前1个回答
1年前1个回答
SQL查询语句,根据时间段查询某个特定条件的数据,写法报错,
1年前1个回答
你能帮帮他们吗