Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何编写查询结果,求和到不同选项卡中的列_Sql_Sql Server_Sql Server 2008_Sql Server 2012 - Fatal编程技术网

Sql 如何编写查询结果,求和到不同选项卡中的列

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

我可以对两列求和,但按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 
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;

非常简单的聚合查询--
将表连接在一起,并使用
求和
分组方式
。。。