如何在计数后合并两行并合并两个表

时间:2019-03-28 09:04:29

标签: sql

我正在尝试对两个表进行计数并通过联合来得出结果。之后我该如何获取行的总和?

select count(PARTNER_ID) from Administrator.PARTNERS
union 
select count(RECORD_ID) from Administrator.DELETED_RECORDS WHERE RECORD_BASE_TYPE = 'PARTNER'

1 个答案:

答案 0 :(得分:3)

使用子查询

select sum(val)
from
(
select count(PARTNER_ID) as val from Administrator.PARTNERS
union all
select count(RECORD_ID) from Administrator.DELETED_RECORDS WHERE RECORD_BASE_TYPE = 'PARTNER'
)A