Window Functions in SQL

 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

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...