← sources

When do you actually use window functions instead of GROUP BY?

source: reddit (reddit:database)published 2026-10-31 18:16ingested 2026-11-01 02:39

retained text

I've been using `GROUP BY` for aggregations for a while, but I still find window functions a little confusing when deciding which approach makes more sense.

For example, if I need the highest salary in each department, I could use aggregation or a window function like `RANK()` or `ROW_NUMBER()`, depending on what I need in the result.

How do you usually decide between these approaches? Are there situations where window functions are clearly the better choice?

I'd appreciate some practical examples that helped you understand when to use one over the other.

document fetched 2026-11-01 00:34 · canonical https://reddit.com/r/Database/comments/1xkhbic/when_do_you_actually_use_window_functions_instead