SELECT p.id
FROM Products p
WHERE (
        SELECT COALESCE(SUM(sb.quantity), 0)
        FROM Stock_Balance sb
        WHERE
            sb.productId = p.id
    ) < p.minimumStockAlertLevel
ORDER BY (
        p.minimumStockAlertLevel - (
            SELECT COALESCE(SUM(sb.quantity), 0)
            FROM Stock_Balance sb
            WHERE
                sb.productId = p.id
        )
    ) DESC
LIMIT 10
