0% found this document useful (0 votes)
237 views8 pages

Taller-DataBase Workshop

Uploaded by

Manuel Rojas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views8 pages

Taller-DataBase Workshop

Uploaded by

Manuel Rojas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

TALLER DATA BASE WORKSHOP

Presentador por:

CRISTIAN CAMILO ESPEJO RODRÍGUEZ


JOHAN SEBASTIAN SAFI RODRIGUEZ
MANUEL ALBERTO ROJAS

Presentado a:

ANGELA JULIETH HERNANDEZ


CACERES

ESCUELA TECNOLOGICA INSTITUTO TECNICO CENTRAL.


Programa Ingeniería de Sistemas.
BASES DE DATOS III
Bogotá
2020.
2020. Copyright © 2020 por CRISTIAN CAMILO ESPEJO RODRIGUEZ, JOHAN
SEBASTIAN SAFI RODRIGUEZ, MANUEL ALBERTO ROJAS Todos los derechos
reservados.
Data Base Workshop taller

1. Se siguieron los parámetros de descarga e importación de la BD :


https://www.postgresqltutorial.com/postgresql-sample-database/
2. Evidencias de la BD dvdretanl de manera local.
3. Using SQL Window functions:

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 (

SELECT fil.title as title, COUNT(*) as


quantity_of_Rents,
DATE_PART('day', MAX(ren.rental_date) - MIN(ren.rental_date)) AS difference,
MIN(ren.rental_date) first_Rental,
MAX(ren.rental_date) last_Rental,

ROUND((DATE_PART('day', MAX(ren.rental_date) -
MIN(ren.rental_date))/COUNT(*))::numeric,2) as frequency_of_Rents_in_days

FROM rental ren

INNER JOIN inventory inv USING (inventory_id) INNER


JOIN film fil USING (film_id)
group by fil.title
order by fil.title
) as filmsrotation

WHERE difference > 40 AND quantity_of_Rents < 10 ORDER BY


frequency_of_Rents_in_days DESC

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:

DROP SEQUENCE sequence_id;


CREATE SEQUENCE sequence_id;
SELECT
nextval('sequence_id') as Ranking,
CONCAT(cus.first_name,' ', cus.last_name) as Customer,
SUM(pay.amount) as Spendamount,
(SELECT SUM(amount) FROM payment) as Totalrentamount,
ROUND((SUM(pay.amount)/(SELECT SUM(amount) FROM payment))*100,2) as
ofGrantTotal
FROM customer cus
INNER JOIN payment pay USING (customer_id)
GROUP BY cus.first_name, cus.last_name
ORDER BY SUM(pay.amount) DESC

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:

You might also like