-- 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;