My issue
Intermediate SQL Project - ABC Retail
My code
/* Write a query to perform the following
- Join the tables - 'product_catalog' and division_product_sales'
- Output product_id, units_sold and month from the joined table
- Remember the condition - we need to identify the worst performing month for each product_id in terms of units sold
- Order by product_id */
SELECT
pc.product_id,
dps.units_sold,
dps.month
FROM
product_catalog pc
JOIN
division_product_sales dps ON pc.product_id = dps.product_id
WHERE
(pc.product_id, dps.units_sold, dps.month) IN (
SELECT
dp.product_id,
dp.units_sold,
dp.month
FROM
division_product_sales dp
WHERE
dp.units_sold = (
SELECT
MIN(units_sold)
FROM
division_product_sales
WHERE
product_id = dp.product_id
)
)
ORDER BY
pc.product_id;
Learning course: Learn Data Analytics using SQL and Python
Problem Link: Intermediate SQL Project - ABC Retail Practice Problem in Data Analytics using SQL and Python - CodeChef