Skip to content

Instantly share code, notes, and snippets.

@andrewscaya
Created November 4, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewscaya/945c69b0666791cfee1ade1b89deeea1 to your computer and use it in GitHub Desktop.
Save andrewscaya/945c69b0666791cfee1ade1b89deeea1 to your computer and use it in GitHub Desktop.
SELECT
day,
month,
year,
sum(total)
FROM
revenue
GROUP BY GROUPING SETS (
(day, month, year),
(month, year),
(year)
);
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
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