处理考勤打卡记录问题
--打卡记录表
CREATE TABLE OriginalData([id] int IDENTITY(1,1),EmployeeID int,CheckTime datetime)
INSERT INTO OriginalData
SELECT 1, '2007-06-11 08:01 ' UNION ALL
SELECT 1, '2007-06-11 12:02 ' UNION ALL
SELECT 1, '2007-06-11 13:05 ' UNION ALL
SELECT 1, '2007-06-11 17:40 ' UNION ALL
SELECT 1, '2007-06-11 19:00 ' UNION ALL
SELECT 1, '2007-06-11 23:42 ' UNION ALL
SELECT 1, '2007-06-11 23:58 ' UNION ALL
SELECT 1, '2007-06-12 07:50 ' UNION ALL
SELECT 1, '2007-06-12 12:00 ' UNION ALL
SELECT 3, '2007-06-11 20:00 ' UNION ALL
SELECT 3, '2007-06-12 04:00 ' UNION ALL
SELECT 3, '2007-06-12 07:55 ' UNION ALL
SELECT 3, '2007-06-12 12:00 ' UNION ALL
SELECT 3, '2007-06-12 13:00 ' UNION ALL
SELECT 3, '2007-06-12 17:35 '
--考勤表
CREATE TABLE OnOffDutyData(EmployeeID int,CheckDate datetime
,OnDuty1 datetime,OffDuty1 datetime
,OnDuty2 datetime,OffDuty2 datetime
,OnDuty3 datetime,OffDuty3 datetime
,OnDuty4 datetime,OffDuty4 datetime)
INSERT INTO OnOffDutyData (EmployeeID,CheckDate)
SELECT 1, '2007-06-11 ' UNION ALL
SELECT 1, '2007-06-12 ' UNION ALL
SELECT 3, '2007-06-11 ' UNION ALL
SELECT 3, '2007-06-12 '
SELECT * FROM OriginalData
SELECT * FROM OnOffDutyData
/*
想要的初始化结果:
EmployeeID CheckDate OnDuty1 OffDuty1 OnDuty2 OffDuty2 OnDuty3 OffDuty3 OnDuty4
1 2007-06-11 08:01 12:02 13:05 17:40 19:00 23:42 07:50 --(07:50为第2天的第一次打卡记录)
1 2007-06-12 07:50 12:00 NULL NULL NULL NULL NULL
3 2007-06-11 20:00 04:00 (04:00 为第2天第1次打卡,其他段为如上行为NULL)
4 2007-06-12 04:00 07:55 12:00 13:00 17:35 NULL NULL
--方法说明:
按EmployeeID 和 打卡日期 CONVERT(nchar(10),CheckTime,120) ,每天提取当天前6次打卡记录和第2天第一次打卡记录
UPDATE 考勤表(OnOffDutyData)。
打卡记录表数据大小: 5000(人)×30(天)×6(大约每天的打卡次数)=90万条记录
考勤表数据大小: 5000(人)×30(天)=15万条记录
要求一个能提高效率的Update方法,具体实现方法不限。
*/
DROP TABLE OriginalData,OnOffDutyData
--分数不够到时候再补,先放100分!
------解决方案--