我有一张这样的表:
ID Time-in-out
1122 08:00
1122 17:00
221 09:00
221 15:00
我需要这样的输出:
ID Time-in Time-Out
1122 08:00 17:00
221 09:00 15:00
我该怎么做?
答案 0 :(得分:0)
简单如下:
CREATE TABLE tab(id INT, time_in_out TIME(0));
INSERT INTO tab(id, time_in_out)
SELECT 1122, '08:00'
UNION ALL
SELECT 1122, '17:00'
UNION ALL
SELECT 221, '09:00'
UNION ALL
SELECT 221, '15:00'
SELECT
[id],
[time_in] = MIN(time_in_out),
[time_out] = MAX(time_in_out)
FROM tab t
GROUP BY id
或者你可以使用PIVOT。