如何编写查询结果,总和到不同tabele中的列

时间:2016-02-26 13:17:35

标签: sql sql-server sql-server-2008 sql-server-2012

我可以将 idprice tabel A 组合两列,

enter image description here

3 个答案:

答案 0 :(得分:0)

试试这个:

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

SQLFiddle

答案 1 :(得分:0)

<强>查询

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;

答案 2 :(得分:-1)

试试这个

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