Day+11+-+Course+slides
Day+11+-+Course+slides
Window functions
SELECT
transaction_id,
payment_type, No. of rows not affected
customer_id,
price_in transaction,
(SELECT SUM(price_in_transaction) Aggregated by
FROM sales s2
WHERE s2.customer_id=s1.customer_id)
FROM sales s1
Window functions
SELECT
transaction_id,
payment_type, No. of rows not affected
customer_id,
price_in transaction,
SUM(price_in_transaction) OVER(PARTITION BY customer_id) Aggregated by
FROM sales s
Window functions
SELECT
transaction_id,
payment_type, No. of rows not affected
customer_id,
price_in transaction,
COUNT(*) OVER(PARTITION BY customer_id) Aggregated by
FROM sales s
Window functions
SELECT
transaction_id,
payment_type, No. of rows not affected
customer_id,
price_in transaction,
COUNT(*) OVER(PARTITION BY payment_type) Aggregated by
FROM sales s
Window functions
Window
Write a query that returns the list of movies including
- film_id,
- title,
- length,
- category,
- average length of movies in that category.
Result
Write a query that returns all payment details including
- the number of payments that were made by this customer
and that amount
Result
Write a query that returns the running total of how late the flights are
(difference between actual_arrival and scheduled arrival) ordered by flight_id
including the departure airport.
As a second query, calculate the same running total but partition also by the
departure airport.
Result
Write a query that returns the customers' name, the country and how many
payments they have. For that use the existing view customer_list.
Afterwards create a ranking of the top customers with most sales for each
country. Filter the results to only the top 3 customers per country.
Result
Write a query that returns the revenue of the day and the revenue of the
previous day.
Result
Write a query that calculates now the share of revenue each staff_id makes per
customer. The result should look like this:
Hint
You need to use a subquery.