Ordering
Eliminating duplicate results
Aggregation
Grouping
18. Find the average value in groups
HAVING: filtering and ordering groups
Let's practice

Instruction

That's right!

Let's study one more example of this kind:

SELECT
  customer_id, 
  avg(total_sum) 
FROM orders 
GROUP BY customer_id;

As you can see, we now have the function avg(total_sum) which will count the average order value for each of our customers.

Exercise

Find the average salary in each department in 2015.

Stuck? Here's a hint!

Type:

SELECT 
  department, 
  avg(salary) 
FROM employees 
WHERE year = 2015 
GROUP BY department;