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;