Qweque Brako Qweque Brako - 4 months ago 10
SQL Question

summing two colums of a table and display in html table

I am trying to sum two columns of the same table row by row but my code gives me the total of the two tables.

id Price 1 price 2
1 20 20
2 40 30


i want to sum the sum of each row and display in html table looking like this

id Total
1 40
2 70


This is my sql code

Select sum( price1+price2) from table

Answer
SELECT (price1+price2) as total_price FROM table

SUM is an aggregation function : it aggregates all records found and does the sum.

price1 + price2 sums this two columns for each record separatly.