问题
I do understand window functions and group by separately.
But what happens when you use both a window function and a group by clause in the same query ?
- Are the selected rows grouped first, then considered by the window function ?
- Or does the window function executes first, then the resulting values are grouped by
group by
? - Something else ?
回答1:
Quote from the manual:
If the query contains any window functions, these functions are evaluated after any grouping, aggregation, and HAVING filtering is performed
emphasis mine
来源:https://stackoverflow.com/questions/37293435/how-do-window-functions-and-the-group-by-clause-interact