1-- It accepts a single column as a parameter and returns "1"
2-- if the column contains a null value generated as part of a
3-- subtotal by a ROLLUP or CUBE operation or "0" for any other value,
4-- including stored null values
5
6SELECT fact_1_id,
7 fact_2_id,
8 SUM(sales_value) AS sales_value,
9 GROUPING(fact_1_id) AS f1g,
10 GROUPING(fact_2_id) AS f2g
11FROM dimension_tab
12GROUP BY CUBE (fact_1_id, fact_2_id)
13HAVING GROUPING(fact_1_id) = 1 OR GROUPING(fact_2_id) = 1
14ORDER BY GROUPING(fact_1_id), GROUPING(fact_2_id);