What is the difference between window functions and aggregate functions?
π‘ Model Answer
Aggregate functions (e.g., SUM, COUNT, AVG) collapse a set of rows into a single value and are used in the GROUP BY clause. They return one row per group.
Window functions, on the other hand, perform calculations across a set of rows related to the current row (the window) while preserving the original row count. They are written with OVER() and can include PARTITION BY and ORDER BY clauses. Window functions allow you to compute running totals, moving averages, rankings, and more without collapsing rows.
In short, aggregates reduce the number of rows; window functions enrich each row with additional computed values.
This answer was generated by AI for study purposes. Use it as a starting point β personalize it with your own experience.
π€ Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers β invisible to screen sharing.
Get Assisting AI β Starts at βΉ500