Assignment
University
California State UniversityCourse
IS 441 | Database Management SystemsPages
2
Academic year
2023
Alicia Webb
Views
0
12/09/2023 Answer this question below. 1. Make a SQL Query to display category film with the highest rental count Answer : SELECT c.name, count(r.rental_id) as rental_count FROM category c LEFT JOIN film_category fc ON c.category_id = fc.category_id LEFT JOIN film f ON fc.film_id = f.film_id LEFT JOIN inventory i ON f.film_id = i.film_id LEFT JOIN rental r ON i.inventory_id = r.inventory_id GROUP BY 1 ORDER BY 2 DESC LIMIT 5 Here’s the output when we run the query : 2. Make a SQL Query to display 10 customers who always returned film late. Answer : SELECT c.customer_id, c.first_name, c.last_name, count(*) AS late_return_count FROM customer AS c JOIN rental AS r ON c.customer_id = r.customer_id WHERE r.return_date > r.rental_date GROUP BY c.customer_id, c.first_name, c.last_name ORDER BY 4 desc
LIMIT 10 Here’s the output when we run the query :
PostgreSQL Practice #8
Please or to post comments