You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- ROLLUP() with one argument SELECT AUTHOR_ID, COUNT(*)
FROM T_BOOK
GROUP BY ROLLUP(AUTHOR_ID)
-- ROLLUP() with two argumentsSELECT AUTHOR_ID, PUBLISHED_IN, COUNT(*)
FROM T_BOOK
GROUP BY ROLLUP(AUTHOR_ID, PUBLISHED_IN)
With UNION ALL:
-- The same query using UNION ALL:SELECT AUTHOR_ID, COUNT(*) FROM T_BOOK GROUP BY (AUTHOR_ID)
UNION ALLSELECTNULL, COUNT(*) FROM T_BOOK GROUP BY ()
ORDER BY1 NULLS LAST
-- The same query using UNION ALL:SELECT AUTHOR_ID, PUBLISHED_IN, COUNT(*)
FROM T_BOOK GROUP BY (AUTHOR_ID, PUBLISHED_IN)
UNION ALLSELECT AUTHOR_ID, NULL, COUNT(*)
FROM T_BOOK GROUP BY (AUTHOR_ID)
UNION ALLSELECTNULL, NULL, COUNT(*)
FROM T_BOOK GROUP BY ()
ORDER BY1 NULLS LAST, 2 NULLS LAST
lukaseder
changed the title
Simulate ROLLUP, CUBE, and GROUPING SETS where they're not supported natively
Emulate ROLLUP, CUBE, and GROUPING SETS where they're not supported natively
May 2, 2019
Here's how:
With
UNION ALL
:This is also nicely explained here:
http://msdn.microsoft.com/en-us/library/bb510427(v=sql.105)
Prerequisites for this task:
GroupField
typeGROUP BY()
supportThe text was updated successfully, but these errors were encountered: