请教一个关于考勤的sql语句

现需要从原始表A中统计一考勤结果,要求21点至24点(210000<=x<=240000)间刷过卡的人记作一次打卡(无论其刷过几次),统计所有人的每天打卡记录。原始表A中有打卡的日期,时间,工号。结果样例:日期             工号      打卡20120201     0001      120120201     0002      120120202     0001      1

select 日期,工号,min(时间) 时间 from 表A where 时间 between 21000 and 24000 group by 日期,工号
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-16
oracle 字段t1:商家cd t2:托盘cd t3:空数量
--测试过,能用,不知是否满足要求?
select t.t1,
sum (decode(t.t2, 'm1' ,t.t3,0))m1,
sum (decode(t.t2, 'm2' ,t.t3,0))m2,
sum (decode(t.t2, 'm3' ,t.t3,0))m3,
sum (decode(t.t2, 'm4' ,t.t3,0))m4,
sum (decode(t.t2, 'm8' ,t.t3,0))m8
from a t
group by t.t1

关键就是日期那,存的字段是2011-08-17形式,但是统计的时候是按月统计的
第2个回答  2012-03-12
select distinct 日期,工号,1 as 打卡 from A where +时间条件(210000<=x<=240000)
相似回答