Interview Question

What are window functions?

Window functions calculate across row sets while preserving individual rows.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

A window function calculates across related rows without collapsing them into one row per group. • OVER defines the window specification. • PARTITION BY creates independent partitions. • ORDER BY and a frame can define row sequence and the rows used by the calculation.

💡 SQL Example

SELECT name, salary, AVG(salary) OVER (PARTITION BY department_id) AS department_average FROM employees;

Result

Each employee row with its department average

⚡ Quick Revision

Window functions calculate across row sets while preserving individual rows.