I have the following query which works fine when bringing out the total price of each order (thanks to the stackoverflow community):
SELECT sum((ordered_items.price + ordered_items.vat) * ordered_items.qty) + orders.postage_price + orders.postage_vat as total_price
FROM orders
JOIN ordered_items
ON orders.id_orders = ordered_items.order_id
GROUP BY orders.id_orders
However I also want to bring out the total amount of all the orders added together. I have tried taking off the GROUP BY but this returns the wrong price. I've figured that it's adding up all the items correctly, but then only adding on one postage.
- ordered_items - includes all the items ordered (so there can be multiple rows)
- orders - includes the postage price of the order (there will only ever be one row per order here)
Many thanks in advance for any help.