1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AGEDESCONQUET'
AND nt.product_quantity_requested - nt.product_quantity_...' at line 8
WITH tfts
AS
(SELECT
nt.product_model,
nt.product_origin AS product_location,
-SUM(nt.product_quantity_requested - nt.product_quantity_declined - nt.product_quantity) AS Q
FROM netshop_transfer nt
WHERE nt.product_model = 'L'AGEDESCONQUET'
AND nt.product_quantity_requested - nt.product_quantity_declined > nt.product_quantity
AND nt.product_owner_id < 100000
AND nt.product_supplier_id < 100000
GROUP BY nt.product_model,
nt.product_owner_id,
nt.product_supplier_id,
nt.product_price_stock,
nt.product_origin), reserv
AS
(SELECT
p.products_model,
c.customers_shop_id AS product_location,
SUM(-nca.customers_alerts_quantity) AS QRes
FROM netshop_customers_alerts nca
INNER JOIN products p
ON p.products_model = nca.customers_alerts_products_model
INNER JOIN customers c
ON c.customers_nbr = nca.customers_alerts_customers_nbr
WHERE nca.customers_alerts_status < 3
AND nca.customers_alerts_products_model = 'L'AGEDESCONQUET'
AND nca.customers_alerts_used = 0
GROUP BY c.customers_shop_id,
p.products_model), stocks
AS
(SELECT
ns.product_model,
ns.product_location,
SUM(ns.product_quantity) AS Q
FROM netshop_stock ns
WHERE ns.product_model = 'L'AGEDESCONQUET'
AND ns.product_isdefect = 0
AND ns.product_owner_id < 100000
AND ns.product_supplier_id < 100000
GROUP BY ns.product_model,
ns.product_owner_id,
ns.product_supplier_id,
ns.product_price_stock,
ns.product_location), merged
AS
(SELECT
*
FROM stocks
UNION ALL
SELECT
*
FROM tfts
UNION ALL
SELECT
*
FROM reserv), stock_minus_transfer_reserv
AS
(SELECT
product_model,
product_location,
nsp.shops_name,
SUM(Q) AS product_quantity
FROM merged
INNER JOIN netshop_shops nsp
ON nsp.shops_id = merged.product_location
WHERE nsp.shops_visible = 1
GROUP BY product_model,
product_location
HAVING SUM(Q) > 0)
SELECT
SUM(smtr.product_quantity) AS qty
FROM stock_minus_transfer_reserv smtr
INNER JOIN netshop_shops ns
ON ns.shops_id = smtr.product_location
INNER JOIN products p
ON p.products_model = smtr.product_model
WHERE ns.shops_group_id = 1
AND p.products_stock_managed = 'True'