我使用分组集计算总金额
SELECT
CASE
WHEN GROUPING(Name) = 1 THEN 'TOTAL' ELSE Name END,
ID,
SUM(Amount)
FROM Table1 GROUP BY GROUPING SETS ( (ID, Name), (ID) );
我会得到这样的东西
ID Name Amount
11 company1 100
11 company1 200
11 TOTAL 300
22 company2 100
22 company2 200
22 TOTAL 300
但我想将名称“TOTAL”更改为“comany1 -total”或“company2-total”,例如
ID Name Amount
11 company1 100
11 company1 200
11 company1-TOTAL 300
22 company2 100
22 company2 200
22 company2-TOTAL 300
有可能这样做吗?我坚持了一段时间。谢谢!!!