Ejemplos sentencias sql

Actores con más de 10 películas

select first_name, last_name, count(film_id) peliculas from
actor join film_actor using (actor_id)
group by first_name,last_name
having peliculas>30

Países con más de 10 ciudades

select country, count(city) cities
from country join city using (country_id)
group by country
having cities>10

Los diez países que más gastan

select country, sum(amount) total, avg(amount) media
from country join city using (country_id)
join address using (city_id)
join customer using (address_id)
join payment using (customer_id)
group by country
order by total desc
limit 0,10

El actor con más películas

select first_name, last_name, count(film_id) peliculas
from actor join film_actor using(actor_id)
group by first_name,last_name
order by peliculas desc
limit 1

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos