Imran Hafeez - 4 months ago 6x

MySQL Question

I am using this code for calculate all numbers. I have added price/number (10) in all table

`$SQL = "SELECT p1 + p2 + p3 + p4 - p0 as total_price from table WHERE id = '1'";`

This query works for me like, first sum all table p1=10 + p2=10 ..... result 40 minus p0=2 total price 38.

but I want to subtract p0 from all columns like

"p1 = 10" - "p0 = 2" = 8

"p2 = 10" - "p0 = 2" = 8

"p3 = 10" - "p0 = 2" = 8

"p4 = 10" - "p0 = 2" = 8

and sum p1+p2+p3+p4 final result = 32

Source (Stackoverflow)

Comments