SQL: Combine Select count(*) from multiple tables

后端 未结 8 624
迷失自我
迷失自我 2020-12-08 13:08

How do you combine multiple select count(*) from different table into one return?

I have a similar sitiuation as this post

but I want one return.

I t

相关标签:
8条回答
  • 2020-12-08 14:09
    select 
      (select count(*) from foo) as foo
    , (select count(*) from bar) as bar
    , ...
    
    0 讨论(0)
  • 2020-12-08 14:10

    You can combine your counts like you were doing before, but then you could sum them all up a number of ways, one of which is shown below:

    SELECT SUM(A) 
    FROM
    (
        SELECT 1 AS A
        UNION ALL 
        SELECT 1 AS A
        UNION ALL
        SELECT 1 AS A
        UNION ALL
        SELECT 1 AS A
    ) AS B
    
    0 讨论(0)
提交回复
热议问题