在sql查询中加入两个计数

时间:2011-01-10 08:59:50

标签: sql

是否可以在一个查询中包含下两个查询的总和?

select COUNT(1) 
from BinaryAssets.BinaryAssetsTags
where TagId = 1731

select COUNT(1) 
from Planning.ScheduleTag
where TagId = 1731

第一个查询的结果是3,例如,从第二个2.我想要一个查询,让我回到5。

2 个答案:

答案 0 :(得分:6)

SELECT 
(select COUNT(1) from BinaryAssets.BinaryAssetsTags where TagId = 1731) 
+ 
(select COUNT(1) from Planning.ScheduleTag where TagId = 1731) 
AS total_sum

答案 1 :(得分:2)

您可以按照以下语法进行操作

select (select Count(1) from a)+(select Count(1) from b) as 'Total Count'