Skip to content

Instantly share code, notes, and snippets.

@carlineng
Created January 21, 2023 04:46
Show Gist options
  • Save carlineng/7fe9b23a2137e08bc6f8f8751125df7c to your computer and use it in GitHub Desktop.
Save carlineng/7fe9b23a2137e08bc6f8f8751125df7c to your computer and use it in GitHub Desktop.
SELECT
YEAR(d_date) AS d_year
, MONTH(d_date) AS d_month
, ROUND(SUM(total_sales), 2) AS total_sales
FROM sales_by_date
GROUP BY ROLLUP (d_year, d_month)
ORDER BY d_year NULLS FIRST, d_month NULLS FIRST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment