miercoles20 bootcamp.txt 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
//1
select customer.first_name from customer 
join rental on customer.customer_id=rental.customer_id
where customer.customer_id=rental.customer_id;

//2
select customer.first_name,film.title from customer 
join rental on customer.customer_id=rental.customer_id
join payment on  payment.rental_id=rental.rental_id
join inventory on rental.inventory_id=inventory.inventory_id
join film on inventory.film_id=film.film_id
where customer.customer_id=rental.customer_id and rental.rental_id=payment.rental_id
and rental.return_date<payment.payment_date;

//3
select category.name , Count(rental.rental_id) from rental
join inventory on rental.inventory_id=inventory.inventory_id
join film on inventory.film_id=film.film_id
join film_category on film_category.film_id=film.film_id
join category on category.category_id=film_category.category_id
Group by category.name
order by Count(rental.rental_id) desc;

//4
select cu.first_name,cu.customer_id , category.name , Count(rental.rental_id) from rental
join inventory on rental.inventory_id=inventory.inventory_id
join film on inventory.film_id=film.film_id
join film_category on film_category.film_id=film.film_id
join category on category.category_id=film_category.category_id
join customer cu on cu.customer_id=rental.customer_id 
Group by category.name,cu.customer_id
order by Count(rental.rental_id) desc;

//5
Select lan.name,count(lan.language_id) from rental ren 
join inventory inv on inv.inventory_id=ren.inventory_id
join film fi on inv.film_id=fi.film_id
join language lan on lan.language_id=fi.language_id
group by lan.name;

//6
select st.first_name, count(r.rental_id) from staff st
join payment pay on st.staff_id=pay.staff_id
join rental r on r.rental_id=pay.rental_id
group by st.first_name
order by count(r.rental_id) desc; 

//7
select ac.actor_id,ac.first_name,count(rental_id)  from actor ac
join film_actor fa on fa.actor_id=ac.actor_id
join film f on f.film_id=fa.film_id 
join inventory inv on inv.film_id=f.film_id
join rental r on r.inventory_id=inv.inventory_id
group by ac.first_name,ac.actor_id 
order by count(r.rental_id) desc; 

//8
select cu.first_name,count(rental_id) from customer cu
join rental r on cu.customer_id=r.customer_id
group by cu.first_name
order by count(r.rental_id) desc;