用max() 函数
WITH T as (
SELECT 'A' [A],'2022-04-01 14:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-04-01 15:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-04-01 17:04:55' [TIME_]
UNION ALL
SELECT 'B' [A],'2022-04-01 14:04:55' [TIME_]
UNION ALL
SELECT 'B' [A],'2022-04-01 15:04:55' [TIME_]
UNION ALL
SELECT 'C' [A],'2022-04-01 17:04:55' [TIME_]
)
SELECT A,MAX(TIME_) [TIME_] FROM T GROUP BY A
逐月max
WITH T as (
SELECT 'A' [A],'2022-04-01 14:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-04-01 15:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-05-01 17:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-05-01 14:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-06-01 15:04:55' [TIME_]
UNION ALL
SELECT 'A' [A],'2022-06-01 17:04:55' [TIME_]
)
SELECT A,CONVERT(NVARCHAR(10),TIME_,120) FROM T GROUP BY A,CONVERT(NVARCHAR(10),TIME_,120)