select tab1.id,max(tab1.c)time from(select distinct(well.DowPersonnelId)id,case when well.intime between '2014-08-01 23:00:00.000' and'2014-08-02 22:59:59.000' then min(well.InTime) end as c
from PerInOutWell well where well.DowPersonnelId in (1,3,4,5,16)group by well.DowPersonnelId,well.InTime )as tab1 group by tab1.id order by tab1.id
大概目的是要从下表(1)查询得到表(2)的结果:
表(1)
表(2)