02-14-2019, 12:19 AM
Thank you for your reply.
I did not know the query binding approach. I will deepen it for my developments.
Yes, my request works perfectly.
My problem is that at one point I have to do some qty_alert to compare it to qty.
At this moment the result qty becomes false doubles its value.
Here is the query built:
I did not know the query binding approach. I will deepen it for my developments.
Yes, my request works perfectly.
My problem is that at one point I have to do some qty_alert to compare it to qty.
At this moment the result qty becomes false doubles its value.
Here is the query built:
PHP Code:
SELECT products.id, products.reference, products.label, (SUM(CASE WHEN slug IN ('orders', 'variation', 'transfer', 'add') THEN stocks.qty ELSE 0 END) - SUM(CASE WHEN slug ='used' THEN stocks.qty ELSE 0 END)) as qty, SUM('qty_alert') AS qty_alert
FROM products JOIN stocks ON stocks.id_product = products.id JOIN stock_alert ON stocks_alert.id_product = stocks.id_product
WHERE ( products.reference LIKE '%%' ESCAPE '!' OR products.label LIKE '%%' ESCAPE '!' ) GROUP BY products.id HAVING qty < qty_alert;