日期:2014-05-17 浏览次数:20575 次
with Attendance(WorkID,Atd_Datetime)as(
select 111111,'2013-06-01 7:55' union all
select 111111,'2013-06-01 7:58' union all
select 111111,'2013-06-01 8:55' union all
select 111111,'2013-06-01 18:08' union all
select 111111,'2013-06-01 20:09' union all
select 222222,'2013-06-01 7:58' union all
select 222222,'2013-06-01 18:22')
select * from (
select WorkID,MIN(atd_datetime)atd_datetime,'上班'type from (
select workid,CONVERT(datetime,atd_datetime)atd_datetime from Attendance
)A
group by WorkID,CONVERT(varchar,atd_datetime,23)
union all
select WorkID,max(atd_datetime)atd_datetime,'下班'type from (
select workid,CONVERT(datetime,atd_datetime)atd_datetime from Attendance
)A
group by WorkID,CONVERT(varchar,atd_datetime,23)
)a order by 1,2