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.

14 lines
580 B

-- Query 4: Filtered version of query 3, to only show shops with at least 1M in sales
SELECT
outlet_lookup.shop_name,
SUM(shop_facts.amount_sold) AS total_amount_sold,
SUM(shop_facts.quantity_sold) AS total_quantity_sold
FROM outlet_lookup
INNER JOIN shop_facts ON shop_facts.shop_code = outlet_lookup.shop_code
INNER JOIN calendar_year_lookup ON shop_facts.week_key = calendar_year_lookup.week_key
WHERE calendar_year_lookup.year = 2001
GROUP BY outlet_lookup.shop_code, calendar_year_lookup.year
HAVING total_amount_sold >= 1000000
ORDER BY total_amount_sold DESC;