大力可是sql板的顶级高手,你跑这里来问,他看的到才怪

解决方案 »

  1.   

    select empid,empno,
    min(t1) as t1,
    min(t2) as t2,
    min(t3) as t3,
    min(t4) as t4
    from (
    select empid,empno,kqdate,
    case when (select count(*) from c where empid=x.empid and empno=x.empno and kqdate=x.kqdate and kqtime<=x.kqtime)=1 then kqdate+' '+kqtime end as t1,
    case when (select count(*) from c where empid=x.empid and empno=x.empno and kqdate=x.kqdate and kqtime<=x.kqtime)=2 then kqdate+' '+kqtime end as t2,
    case when (select count(*) from c where empid=x.empid and empno=x.empno and kqdate=x.kqdate and kqtime<=x.kqtime)=3 then kqdate+' '+kqtime end as t3,
    case when (select count(*) from c where empid=x.empid and empno=x.empno and kqdate=x.kqdate and kqtime<=x.kqtime)=4 then kqdate+' '+kqtime end as t4
    from c x
    ) as y
    group by empid,empno,kqdate
    order by empid,empno,kqdate
    go