SQL Window functions¶
ROLLUP¶
- shorthand for defining multiple grouping sets
- really great for calculating groups for sums
SELECT
brand,
segment,
SUM (quantity)
FROM sales
GROUP BY ROLLUP (brand, segment)
ORDER BY brand, segment;
Window Functions¶
See SELECT STAR Julia Evans zine page 14
[expression] OVER ([window definition])
-
Window is a set of rows
-
The window here is just one row
- the window here is each class
PARTITION BY vs GROUP BY
Group by changes the number of rows being returned
PARTITION by is like a group by for one column's calculation
Last update:
2023-04-24