Loading section...

Multiple Windows

Concepts: sqlMultipleWindows

Real-world analysis often requires comparing a row from multiple perspectives in the same query. You might need a rank within a department, a running total across the company, and a comparison to the previous month all in one result set. Multiple Window Definitions Each window function in a query can have its own partitioning, ordering, and framing. This flexibility lets you answer multiple questions in a single pass over the data. Different Partitions Here is a practical example: for each sale, show the rank within its category and the rank across all categories. Different Orderings You can also use different orderings in the same query. This is useful for showing how the same data looks from different angles. Alice earns the most (salary rank 1) but is only the third most senior employee