将一个表的两列相加并显示在html表中


summing two colums of a table and display in html table

我试图逐行求和同一个表的两列,但我的代码给出了这两个表的总数。

id  Price 1   price 2 
1   20          20
2   40          30

我想求每行的总和,并显示在html表格中,看起来像这个

id Total
1    40
2    70

这是我的sql代码

Select sum( price1+price2) from table
SELECT (price1+price2) as total_price FROM table

SUM是一个聚合函数:它聚合找到的所有记录并求和。

price1+price2分别对每条记录的这两列进行求和。

删除SUM,它将聚合所有

Select ( price1+price2) from table
Select id AS Id,ISNULL(price1,0)+ISNULL(price2,0) AS Total from table