You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
775 B

-- Query 2: "rank() by amount sold and quantity sold"
-- From the screenshots, the query should be the same as query 1 of the group-by part,
-- without grouping by year, and with two new columns that rank each shop:
-- - once by turnover (??, assuming that turnover is equal to amount_sold)
-- - once by quantity
SELECT
outlet_lookup.shop_name,
SUM(shop_facts.amount_sold) AS total_amount_sold,
SUM(shop_facts.quantity_sold) AS total_quantity_sold,
RANK()
OVER (ORDER BY total_amount_sold DESC)
AS amount_rank,
RANK()
OVER (ORDER BY total_quantity_sold DESC)
AS quantity_rank
FROM outlet_lookup
INNER JOIN shop_facts ON shop_facts.shop_code = outlet_lookup.shop_code
GROUP BY outlet_lookup.shop_code
ORDER BY amount_rank;