【问题标题】:How do I add two counts in HIVE hql?如何在 HIVE hql 中添加两个计数?
【发布时间】:2021-11-04 08:27:49
【问题描述】:

所以我知道我可以通过使用 select count(*) from table1 来获取一个表的计数;

我试过了 选择(从表 1 中选择计数())表 1, (从表 2 中选择计数())表 2 从双;

但它不起作用。

【问题讨论】:

    标签: sql hive hiveql


    【解决方案1】:

    两种可能的解决方案。交叉连接和Union all + 聚合

    交叉连接:

     select t1.cnt as table1_count, 
            t2.cnt as table2_count
     from
          (select count(*) cnt from table1) t1
           cross join
          (select count(*) cnt from table2) t2 
    

    联合所有+最大聚合:

    select max(t1_cnt) table1_count, max(t2_cnt) table2_count
    from
    (
    select count(*) t1_cnt, 0 t2_cnt from table1
    union all
    select 0 t1_cnty, count(*) t2_cnt from table2
    ) s
    

    【讨论】:

      猜你喜欢
      • 2013-08-14
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多