SQL Server - Sub Query中的多个行

时间:2014-06-11 09:02:19

标签: mysql sql

这个查询工作单行但是,我想减去多行

SELECT(
(SELECT num1 from table1 where T_Type=2) - 
(SELECT num2 from table1 where T_Type=3))as
[SUBSTRACTION]

2 个答案:

答案 0 :(得分:0)

尝试

SELECT t1.num1-t2.num2 from table1 t1,table1 t2 where t1.T_Type=2 and t2.T_Type=3

答案 1 :(得分:0)

如何根据类型对num进行求和并减去这些结果,如下所示:

SELECT (  
(SELECT SUM(num1) FROM table1 WHERE T_Type = 2) -  
(SELECT SUM(num2) FROM table1 WHERE T_Type = 3))