如何将来自不同表的多个选择计数(*)合并为一个返回?
我有与此post类似的情景
但我要一个返回。
我尝试了全部,但它吐出了3个单独的计数行。您如何将它们组合成一个?
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
最佳答案
SELECT
(select count(*) from foo1 where ID = '00123244552000258')
+
(select count(*) from foo2 where ID = '00123244552000258')
+
(select count(*) from foo3 where ID = '00123244552000258')
这是一个简单的方法。
关于sql - SQL:合并多个表中的选择计数(*),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1279569/