My issue
Not able to solve the problem
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 */
WITH ranked_sales AS (
SELECT
pc.product_id,
dps.units_sold,
dps.month,
RANK() OVER (PARTITION BY pc.product_id ORDER BY dps.units_sold ASC) AS rank_num
FROM
product_catalog pc
JOIN
division_product_sales dps ON pc.product_id = dps.product_id
)
SELECT
rs.product_id,
rs.units_sold,
rs.month
FROM
ranked_sales rs
WHERE
rs.rank_num = 1
ORDER BY
rs.product_id;
Learning course: Learn Data Analytics using SQL and Python
Problem Link: Practice Problem in - CodeChef