从配置单元中的多个表中选择count(*)

fumotvh3  于 2021-06-25  发布在  Hive
关注(0)|答案(3)|浏览(320)

我在两个不同的模式中有同名的表。我要做的是在格式中的两个表中进行计数比较
表名:count1:count2
如何通过配置单元查询实现这一点?

guykilcj

guykilcj1#

全部使用:

select 'db1.table_name' table_name, count(col1) count1, count(col2) count2 from db1.table_name
UNION ALL
select 'db2.table_name' table_name, count(col1) count1, count(col2) count2 from db2.table_name
dbf7pr2w

dbf7pr2w2#

尝试完全外部连接

select tt1.cn,tt2.cn from 
    (select count(1) as cn from db1.table) tt1 
full outer join 
    (select count(1) as cn from db2.table ) tt2
on tt1.cn=tt2.cn;
r55awzrz

r55awzrz3#

你可以做一个 cross join count个查询。

select t1.count1,t2.count2
from (select count(*) as count1 from tbl1) t1
cross join (select count(*) as count2 from tbl2) t2

相关问题