我有一张桌子" A"就像在图像中一样,我需要创建一个视图来将数据分组为表" B"。 有什么建议?我会感激每一项提高我技能的投入 感谢
答案 0 :(得分:0)
这应该这样做:
SELECT [USER],
[ACTIVITY],
MIN([HOUR]) AS [START],
MAX([HOUR]) AS [END],
RIGHT('0'+CAST(DATEDIFF(SECOND, CAST(MIN([HOUR]) AS TIME), CAST(MAX([HOUR]) AS TIME)) / 3600 AS VARCHAR), 2)+':'+RIGHT('0'+CAST((DATEDIFF(SECOND, CAST(MIN([HOUR]) AS TIME), CAST(MAX([HOUR]) AS TIME)) / 60) % 60 AS VARCHAR), 2) AS [MINUTE]
FROM TAB_A
GROUP BY [USER],
[ACTIVITY];