SkillsGuide.in

Window Functions (SQL)

💡 Quick Definition: SQL functions that perform calculations across a set of table rows related to the current row without collapsing rows like GROUP BY.

Detailed Explanation & Workplace Application

Window functions like ROW_NUMBER(), DENSE_RANK(), LEAD(), and LAG() with OVER(PARTITION BY ... ORDER BY ...) enable running totals, moving averages, and rankings in a single query.

Practical Syntax / Framework Formula

SELECT employee_name, department, salary,
       AVG(salary) OVER(PARTITION BY department) as dept_avg_salary,
       salary - AVG(salary) OVER(PARTITION BY department) as salary_diff
FROM Employees;