从多个表中选择计数(*) [英] Select count(*) from multiple tables

查看:96
本文介绍了从多个表中选择计数(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从两个具有结果的不同表格(称为tab1和tab2)中选择计数(*):

  Count_1 Count_2 
123 456



我尝试过:

  Count_1 from schema.tab1 union all select count(*)Count_2 from schema.tab2 

但我所有是:

  Count_1 
123
456
pre>

解决方案

  SELECT(
SELECT COUNT(*)
FROM tab1
)AS count1,

SELECT COUNT(*)
FROM tab2
)AS count2
FROM dual


How can I select count(*) from two different tables (call them tab1 and tab2) having as result:

Count_1   Count_2
123       456

?

I've tried this:

select count(*) Count_1 from schema.tab1 union all select count(*) Count_2 from schema.tab2

But all I have is:

Count_1
123
456

解决方案

SELECT  (
        SELECT COUNT(*)
        FROM   tab1
        ) AS count1,
        (
        SELECT COUNT(*)
        FROM   tab2
        ) AS count2
FROM    dual

这篇关于从多个表中选择计数(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆