I have the following SQL. Most of the G1 and G2 are one-to-one relationship. A few are one-to-many relationship. The following SQL will show too many "Total2". Is it possible to remove these Total2 rows when G1 and G2 are one-to-one?
SELECT CASE WHEN GROUPING_ID(G1) = 1 THEN 'Total1' ELSE G1 END,
CASE WHEN GROUPING_ID(G2) = 1 THEN 'Total2' ELSE G2 END,
SUM(a),
SUM(b),
count(*)
FROM data
GROUP BY
G1, G2 WITH ROLLUP