Skip to content

Instantly share code, notes, and snippets.

@sfkeller
Last active February 28, 2018 18:15
Show Gist options
  • Save sfkeller/511418aa3f408dc335be92a8fbbaa73f to your computer and use it in GitHub Desktop.
Save sfkeller/511418aa3f408dc335be92a8fbbaa73f to your computer and use it in GitHub Desktop.
SELECT
CASE WHEN GROUPING(movie.genre) = 1 then 'All Genres' else movie.genre end as Genre,
CASE WHEN GROUPING(customer.gender) = 1 then 'All Genders' else customer.gender end as Gender,
sum(sales.quantity) AS Quantity
FROM factsales sales, dimmovie movie, dimcustomer customer
WHERE sales.movieId = movie.movieId
AND sales.custID = customer.custID
GROUP BY CUBE(movie.genre, customer.gender);
/*
"Action";"f";17
"Action";"m";25
"Action";"All Genders";42
"Non-Action";"f";27
"Non-Action";"m";15
"Non-Action";"All Genders";42
"All Genres";"All Genders";84
"All Genres";"f";44
"All Genres";"m";40
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment