信息表『工号,姓名,迟到次数』T_Worker『Uid,name,lateLog』迟到表『工号,迟到日期,迟到时长』T_Late『Uid,latetime,latelong』
1)查询员工姓名含有O的员工在昨天迟到的时长!(每天只会记一次迟到)
select name, latelong fromT_Late
joinT_Worker on (T_Worker.Uid =T_Late.Uid)
where name LIKE '%O%' and Datediff(d,GETDATE(),latetime)=1
2)跟新表每个员工迟到次数为“上月迟到次数”次数之和
用getdate datediff
update a
set a.latetimes= c.times
from T_Worker a ,T_Late b ,(select a.Uid ,COUNT(1) as times from T_Worker a, late b where a.Uid=b.Uid and b.latetime is not null group by a.Uid) as c
where a.Uid =b.Uid and a.Uid =c.Uid