Sql 如何编写查询结果,求和到不同选项卡中的列
我可以对两列求和,但按idprice分组 试试这个:Sql 如何编写查询结果,求和到不同选项卡中的列,sql,sql-server,sql-server-2008,sql-server-2012,Sql,Sql Server,Sql Server 2008,Sql Server 2012,我可以对两列求和,但按idprice分组 试试这个: select a.idprice, sum(a.tax) + b.price as sum_price from tableA a inner join tableB b on b.idprice = a.idprice group by a.idprice, b.price 试试这个 Select (Sum(A.tax) + Sum(B.Price)) As Result
select
a.idprice,
sum(a.tax) + b.price as sum_price
from
tableA a
inner join
tableB b on b.idprice = a.idprice
group by
a.idprice,
b.price
试试这个
Select (Sum(A.tax) + Sum(B.Price)) As Result
From TableA A Inner Join TableB B on A.idprice = B.idprice
Group By A.idprice
查询
select t1.tax + t2.price as new_col_name
from
(
select idprice, sum(tax) as tax
from table1
group by idprice
) t1
join table2 t2
on t1.idprice = t2.idprice;
非常简单的聚合查询--
将表连接在一起,并使用求和
和分组方式
。。。