SQL:从多个表中组合选择计数(*) [英] SQL: Combine Select count(*) from multiple tables
本文介绍了SQL:从多个表中组合选择计数(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将不同表中的多个 select count(*) 合并为一个 return?
How do you combine multiple select count(*) from different table into one return?
我有一个类似的情况 post
但我想要一个回报.
我尝试了 Union all,但它吐出 3 个单独的计数行.你如何将它们合二为一?
I tried Union all but it spit back 3 separate rows of count. How do you combine them into one?
select count(*) from foo1 where ID = '00123244552000258'
union all
select count(*) from foo2 where ID = '00123244552000258'
union all
select count(*) from foo3 where ID = '00123244552000258'
我使用的是 MS SQL 2005
edit: I'm on MS SQL 2005
推荐答案
SELECT
(select count(*) from foo1 where ID = '00123244552000258')
+
(select count(*) from foo2 where ID = '00123244552000258')
+
(select count(*) from foo3 where ID = '00123244552000258')
这是一个简单的方法.
这篇关于SQL:从多个表中组合选择计数(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文