Window Functions in SQL
🔔 Prelude: Boss: “I need the average sales for 7 days.” Me: “Sure! Which 7 days?” Boss: “All the 7 days!” Me: “Su…Sure…?” 🖋️ Window Functions Window functions are generally applied after aggregate functions like MAX(), MIN(), AVG() to perform calculations across a set of table rows(days before, days after) that are related to the current row(current day). Example Table 1: employees employee_id department_id salary 1 101 5000 2 101 6000 3 101 5500 4 102 7000 5 102 7200 6 102 6800 Example 1: OVER() Without Partitioning Calculate the average salary for all employees: ...