Replacing cube with rollup in Oracle SQL
A homework assignment I have asks the following question:
开发者_JS百科Show how to express \group by cube (a, b, c, d)" using rollup rather than cube.
I really don't have the faintest clue how to do this. Where would I start or where could I look for some help?
Since this is an assignment I will point you to a very good article about GROUP BY, ROLLUP and CUBE by Rob van Wijk.
The two equivalence relations relevant here would be:
GROUP BY CUBE ( set1, …, setn )
≡ GROUP BY GROUPING SETS (all possible combinations between () and (set1, …, setn) )
and the analogy with the cartesian product:
GROUP BY a, ROLLUP(b)
≡ GROUP BY GROUPING SETS (a), GROUPING SETS ((b), ())
≡ GROUP BY GROUPING SETS ((a,b), (a))
精彩评论