我有一张包含以下详细信息的表格
ID statusID logTime
100238 1 2011-07-07 03:48:43.000
100238 2 2011-07-07 03:48:46.000
100238 1 2011-07-07 09:07:57.000
100238 2 2011-07-07 16:12:28.000
100238 1 2011-07-08 02:59:57.000
100238 2 2011-07-08 03:00:00.000
100238 1 2011-07-08 09:26:37.000
100238 2 2011-07-08 14:03:05.000
并且所需的输出应该像
repID ClockIn ClockOut
100238 2011-07-07 03:48:43.000 2011-07-07 03:48:46.000
100238 2011-07-07 09:07:57.000 2011-07-07 16:12:28.000
100238 2011-07-08 02:59:57.000 2011-07-08 03:00:00.000
100238 2011-07-08 09:26:37.000 2011-07-08 14:03:05.000
即.. 如果 statusID 为 1,则 logtime 必须在 ClockIn 列中,如果 statusID 为 2,则 logtime 必须在 ClockOut 列中
我使用了类似的查询
SELECT repID,
ClockIn,
ClockOut from
(SELECT a.eventID,
a.repID,
a.logTime,
CASE WHEN a.statusID = 1 THEN a.logTime ELSE NULL END AS ClockIn,
CASE WHEN b.statusID = 2 THEN b.logTime ELSE NULL END AS ClockOut
FROM tbl_ets_reptimelog a
LEFT JOIN tbl_ets_reptimelog b ON a.repID = b.repID)c
结果就像
repID ClockIn ClockOut
100238 2011-07-07 03:48:43.000 NULL
100238 2011-07-07 03:48:43.000 2011-07-07 03:48:46.000
100238 2011-07-07 09:07:57.000 NULL
100238 2011-07-07 09:07:57.000 2011-07-07 16:12:28.000
100238 2011-07-08 02:59:57.000 NULL
100238 2011-07-08 02:59:57.000 2011-07-08 03:00:00.000
100238 2011-07-08 09:26:37.000 NULL
100238 2011-07-08 09:26:37.000 2011-07-08 14:03:05.000
如何删除 ClockOut 列中出现的带有 NULL 值的额外行
请帮助摆脱这个问题......