Over Partition
Returning richer context
OVER PARTITION is an amazing way to generate summary data within the greater context of a table without needed an additional step to process the SQL query output.
For example, a manager wants a report of their call center agents with both their average handle time (AHT) and their department's overall AHT.
Given a table which looks like this...
A query can be constructed to find the average handle time by agent using OVER PARTITION.
This can also be used to create running totals and averages by limiting the partition using the table row. An example would be to show the running total of an account balance over a number of different accounts.
These can get complex, and should be tested, but can yield a great report, especially when saved as a stored procedure.
Last updated