答案 0 :(得分:0)
您可以按月份分组。可以使用string_agg
来标识ID:
SELECT STRING_AGG([DATA IDs], ','), [Month], SUM([Value])
FROM mytable
GROUP BY [Month]
答案 1 :(得分:0)
select Stuff((SELECT ',' + dataIds
FROM test_agg where month = t.month
FOR xml path('')), 1, 1, '') as "Data Ids", Month, sum(value) as Total from test_agg t group by month;