Taller-DataBase Workshop
Taller-DataBase Workshop
Presentador por:
Presentado a:
Please give us an SQL script in order to know which films have a fewer rotation, so the
requirements are: the difference between the first date of rent and the last date of rent is
greater than 40 days and, the quantity of rents is less than 10 rent over whole time (this analysis
must be done at film level). Show the next columns in the report: Film Title, Quantity of Rents,
Difference in days between first and last rent, First Rental Date, Last Rental Date, Frequency of
Rents in days (Difference in days between first and last rent / Quantity of Rents), the expected
result is showing below:
Consuta:
SELECT * FROM (
ROUND((DATE_PART('day', MAX(ren.rental_date) -
MIN(ren.rental_date))/COUNT(*))::numeric,2) as frequency_of_Rents_in_days
Resultado:
4. We need to know how much money customers spend, so please give a SQL script in order
to obtain: Ranking of customers based on Spend money, name of the customer, Spend
Amount, Total Rent amount (a sum of every rent), and "% of Grant Total" by Customer
(Spend Amount / Total Rent Amount), the expected result is showing below.
Consuta:
Resultado:
5. We need to know the total sales in each country, but specifically the countries in which
rent a film have the most sales. Order them from most to least
Consulta:
SELECT
cou.country,
SUM(amount)
FROM country cou
INNER JOIN city cit ON cit.country_id = cou.country_id
INNER JOIN address adr ON cit.city_id = adr.city_id
INNER JOIN customer cus ON adr.address_id = cus.address_id
INNER JOIN payment pay ON pay.customer_id = cus.customer_id
GROUP BY cou.country
ORDER BY COUNT(*) DESC
Resultado: