题解 | 分析不同门店各类商品的库存情况和销售情况
分析不同门店各类商品的库存情况和销售情况
https://www.nowcoder.com/practice/5b9262a36724466ea1ae1f58187197d6
SELECT
s.store_id,
s.store_name,
p.product_category,
SUM(si.inventory_quantity) AS inventory_quantity,
SUM(si.sales_amount) AS sales_amount
FROM
stores AS s
INNER JOIN
sales_inventory AS si ON s.store_id=si.store_id
INNER JOIN
products AS p ON si.product_id=p.product_id
GROUP BY
s.store_id,
s.store_name,
p.product_id,
p.product_category
HAVING
SUM(si.inventory_quantity)<10 AND SUM(si.sales_amount)>5000
ORDER BY
s.store_id,
p.product_id;

