SQL Advanced (Analytics)
Back to WINDOW FUNCTIONS (ANALYTICS FOCUS)

Window Functions for Analysts

Ranking, running totals, moving averages with OVER().

10 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. GROUP BY Aggregation Review — Review of standard GROUP BY queries collapsing multiple employee rows into single departmental summary records.
  2. Window Function Mechanics — Demonstration of calculating department average salary while preserving individual employee rows in the final output.
  3. Global Windows with OVER — Explanation of the OVER keyword and computing company-wide averages across all rows using empty parentheses.
  4. Partitioning Window Calculations — Applying PARTITION BY to calculate department minimums, maximums, and averages simultaneously alongside employee records.
  5. Ranking Functions and ORDER BY — Introduction of the RANK function combined with global and partitioned ORDER BY clauses to evaluate salary positions.
  6. Window Functions Summary — Recap of OVER, PARTITION BY, and ORDER BY mechanics with a preview of advanced functions like LEAD and LAG.
PDF notes

Frequently asked questions

What happens if I omit PARTITION BY inside the OVER clause?

The function treats the entire result set as one single window and calculates the metric across all rows.

Can I combine different window partitions in the same SELECT statement?

Yes, you can calculate overall metrics using empty OVER alongside department-level metrics using PARTITION BY in a single query.

Can ranking functions like RANK() run without an OVER clause?

No, window-specific functions like RANK, LEAD, and LAG require an OVER clause to define their calculation scope.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.