I have problem with SQL query. If given order contains items, witch does not contains sub-items, then is total price of order zero, otherwise this query works fine.
SELECT o.`id`, o.`date`, c.`name`,
((i.`quantity` * i.`price`) +
SUM(i.`quantity` * subi.`quantity_kg` * subi .`price`)) as total_price
FROM `order` o
JOIN `customer` c ON o.`id_customer`=c.`id`
LEFT JOIN `order_item` i ON i.`id_order`= o.`id`
LEFT JOIN `order_subitem` subi ON si.`id_product`= i.`id_product`
GROUP BY o.`id`
Thank you for help.
Use
coalesceofifnullon your subitem fields:This makes sure, that these fields won’t end up being null ruining your whole calculation. E.g. null+1 = null