blmg2009 Posted May 17, 2015 Share Posted May 17, 2015 Hi there, I'm currently teaching myself PHP and MYSQL, so I'm struggling to think of the way to do the following: I have a table for order_products, this includes a list of all products on a customers order. I have two fields in this table that are price & tax I need to add these to values together to get a total but I also need to run a total all all the products in that order, so for example: Order_product_id order_id Price Tax 1 4 30.00 5.00 Order_product_id order_id Price Tax 2 4 20.00 7.00 Order_product_id order_id Price Tax 3 4 10.00 5.00 I have added all the values of a single field before but never had to add two fields together and get all other totals If anyone has the answer to my problem it would be greatly appreciated Thanks for reading. Quote Link to comment https://forums.phpfreaks.com/topic/296360-adding-two-mysql-value-fields-and-getting-a-total/ Share on other sites More sharing options...
blmg2009 Posted May 17, 2015 Author Share Posted May 17, 2015 Currently i'm thinking of running the total for both columns and then adding them, but is there a better way? Quote Link to comment https://forums.phpfreaks.com/topic/296360-adding-two-mysql-value-fields-and-getting-a-total/#findComment-1512065 Share on other sites More sharing options...
Barand Posted May 17, 2015 Share Posted May 17, 2015 SELECT order_id , SUM(price) as total_price , SUM(tax) as total_tax , SUM(price+tax) as total_product FROM order_product GROUP BY order_id Quote Link to comment https://forums.phpfreaks.com/topic/296360-adding-two-mysql-value-fields-and-getting-a-total/#findComment-1512066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.