-- Las funciones de agregado tienen sentido cuando agrupamos -- los valores: GROUP BY -- La sintaxis es select valor, agregado(..) from tabla1 join tabla2 GROUP BY valor -- Cuantas ciudades tiene cada pais select country,count(city) ciudades from country join city on country.country_id=city.country_id group by country; -- Total de pagos por cliente select first_name,last_name,sum(amount) total, avg(amount) media, min(amount) minimo,max(amount) maximo from customer join payment on customer.customer_id=payment.customer_id group by customer.customer_id order by first_name,last_name; -- Total de películas por categoría select name,count(film_id) total from category join film_category on category.category_id=film_category.category_id group by category.category_id order by total desc;