select a.store_id, c.store_name, product_category, qty as inventory_quantity, amt as sales_amount
from (
select store_id, product_id,
sum(inventory_quantity) as qty,
sum(sales_amount) as amt
from sales_inventory
group by store_id, product_id
) a join products b on a.product_id=b.product_id
join stores c on a.store_id=c.store_id
where qty<10 and amt>5000
order by a.store_id, a.product_id

京公网安备 11010502036488号