Created
November 4, 2016 19:49
-
-
Save andrewscaya/945c69b0666791cfee1ade1b89deeea1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
day, | |
month, | |
year, | |
sum(total) | |
FROM | |
revenue | |
GROUP BY GROUPING SETS ( | |
(day, month, year), | |
(month, year), | |
(year) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
day, | |
month, | |
year, | |
sum(total) | |
FROM | |
revenue | |
GROUP BY | |
day, month, year | |
UNION | |
SELECT | |
NULL, | |
month, | |
year, | |
sum(total) | |
FROM | |
revenue | |
GROUP BY | |
month, year | |
UNION | |
SELECT | |
NULL, | |
NULL, | |
year, | |
sum(total) | |
FROM | |
revenue | |
GROUP BY | |
year |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
day, | |
month, | |
year, | |
sum(total) | |
FROM | |
revenue | |
GROUP BY ROLLUP(day, month, year); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment