Window Functions in SQL
Window functions are used to perform calculations on a specific subset of rows in a table, without grouping the data. Window functions can be used to calculate running totals, ranks, and other complex calculations. Here's an example:
sql
SELECT name, age, department,
RANK() OVER (PARTITION BY department ORDER BY age DESC) as rank
FROM employees;
In this example, we're using the RANK window function to calculate the rank of each employee within their department based on age. The PARTITION BY clause is used to group the data by department.
No comments:
Post a Comment