My current query only can select one SKU at a time. I can leave salesite_id
constant. If there is a way to also have varying salesite_id
s that would be good too, but not necessary. Also any suggestions on indexes would be much appreciated also.
SELECT
available - (
SELECT COALESCE(sum(quantity), 0)
FROM product_locks
WHERE sku = 'sku1'
) - (
SELECT COALESCE(sum(quantity), 0)
FROM
orderlineitems
INNER JOIN responses_authnets ON responses_authnets.id = orderlineitems.response_id
WHERE
sku = 'sku1' AND responses_authnets.salesite_id = 'site_id_1'
) AS free,
available AS total,
sku,
on_hold
FROM product_inventories
WHERE sku = 'sku1' AND salesite_id = 'site_id_1';