Skip to main content
SQL โ€ข LESSON 68

Aggregate with Filter

How can we calculate the average salary only for engineers?

Intermediateโฑ 3 Minutesโญ 810 XP
๐Ÿค” THE QUESTION

How can we calculate the average salary only for engineers?

๐Ÿ’ก WHAT IS IT?

The WHERE clause restricts rows before aggregation functions are evaluated.

๐ŸŽฏ WHAT IS IT USED FOR?

Segmented averages, department KPIs, filtered spend analytics.

๐Ÿ’ป EXAMPLE
SELECT AVG(salary) AS average_engineering_salary
FROM employees
WHERE department = 'Engineering';

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for Aggregate with Filter.

  • โœ“ Filtered aggregation
  • โœ“ WHERE before aggregate
  • โœ“ Department statistics
  • โœ“ Targeted metrics