I calculate the total amount using grouping sets
SELECT
CASE
WHEN GROUPING(Name) = 1 THEN 'TOTAL' ELSE Name END,
ID,
SUM(Amount)
FROM Table1 GROUP BY GROUPING SETS ( (ID, Name), (ID) );
I will get something like this
ID Name Amount
11 company1 100
11 company1 200
11 TOTAL 300
22 company2 100
22 company2 200
22 TOTAL 300
But I want to change the name 'TOTAL' to 'comany1 -total' or 'company2-total' for example
ID Name Amount
11 company1 100
11 company1 200
11 company1-TOTAL 300
22 company2 100
22 company2 200
22 company2-TOTAL 300
Is it possible to do that? I am stuck on this for a while. Thanks!!!