SQL 2023 · Aggregation and window functions
Filter groups
Keep only groups that meet a condition. WHERE filters rows before grouping, HAVING filters groups after.
SELECT user_id, COUNT(*) FROM orders GROUP BY user_id HAVING COUNT(*) > 5;
Official SQL 2023 documentation
More aggregation and window functions commands
- Count rows
- Group and total
- Number rows within groups
- Compute a running total
- Rank rows
- Compare with the previous row
All aggregation and window functions commands · SQL 2023 cheatsheet