OVER and PARTITION BY
The OVER clause is used with window functions to define a window, or set of rows, for calculations. PARTITION BY divides the result set into partitions to perform calculations on each partition separately.
Example: Using OVER with PARTITION BY
SELECT Name, City, Contribution,
RANK() OVER (PARTITION BY City ORDER BY Contribution) AS ContributionRank
FROM FreedomFighters;
Output:
Ranks contributions within each city.
Notes
- Use
OVERto specify the window for window functions. PARTITION BYdivides the result into groups for calculations.