Queries.sql
Queries.sql
SQL QUERIES
Sl. Task Query
1 Top Customers: Select
Identify the top 10 customer.customer_id,
customers who rent customer.first_name,
the most movies. customer.last_name,
Include their names, customer.email,
total rentals, and Count(rental.rental_id)
contact details From customer
Join rental On customer.customer_id =
rental.customer_id
Group By customer.customer_id,
customer.first_name, customer.last_name,
customer.email
Order By Count(rental.rental_id) desc
Limit 10
2 Rental Trends: A.
Analyze the monthly Select To_Char(rental_date, 'YYYY-MM') As
rental trends for the rental_month,
past year to identify Count(*) As rental_count
peak rental periods. From rental
Where rental_date Between '2020-01-01' And
'2020-12-31'
Group By To_Char(rental_date, 'YYYY-MM')
Order By rental_count desc
B.
Select to_Char(rental_date, 'yyyy-mm') as
rental_month,
Count (*) as rental_count
From Rental
where rental_date between '2005-01-01' and
'2005-12-31'
Group by to_Char(rental_date, 'yyyy-mm')
Order by rental_count desc
Select customer.customer_id,
customer.first_name, customer.last_name,
film.rental_rate, payment.amount, film.title,
SUM(payment.amount-film.rental_rate) As
late_fees
From customer
Join rental On customer.customer_id =
rental.customer_id
Join inventory On rental.inventory_id =
inventory.inventory_id
Join film on inventory.film_id = film.film_id
Join payment On rental.rental_id =
payment.rental_id
Where payment.amount-film.rental_rate > 0
Group By customer.customer_id,
customer.first_name, customer.last_name,
film.rental_rate, payment.amount, film.title
Order By customer.first_name asc
Select
Sum(Extract(Day From Current_Date -
rental.rental_date) * 1) As total_loss
From rental
Where rental.return_date is null