zoukankan      html  css  js  c++  java
  • hive 子查询特别分析

     转自:

    Hive只支持在FROM子句中使用子查询,子查询必须有名字,并且列必须唯一:SELECT ... FROM(subquery) name ...
    确认下是否一定要求列必须唯一? 
       
    建表语句:
     
    create table  tb_in_base
    (
       id  bigint,
       devid bigint,
        devname string
    ) partitioned by (job_time bigint) row format delimited fields terminated by ',';
     
    create table  tb_in_up
    (
       id  bigint,
       devid bigint,
       devname string
    ) partitioned by (job_time bigint) row format delimited fields terminated by ',';
     
     
    场景一:单表子查询没有指定表别名
     
    语句:select * from (select id,devid,job_time from tb_in_base) ;
     
    执行过程:
     
     
     
    提示需要指定子查询源。
     
     
    加上表别名:
     
    语句:select * from (select id,devid,job_time from tb_in_base) a;
     
    执行过程:
     
     
    加了表别名后可以正常输出子查询中的数据。
     
    结果分析:在hive中若有子查询必须指定子查询的表别名
     
    场景二:单表查询外围字段比子查询少一个
     
    语句: select id,devid from (select id,devid,job_time from tb_in_base) a; 
     
    执行过程:
     
     
     
    结果分析:输出外围指定字段的数据可以输出 。
     
    场景三:两张表进行union all
     
    语句:
     
     select a.id,a.devid from (select a.id,a.devid,a.job_time from tb_in_base a union all select b.id,b.devid,b.job_time from tb_in_up b) a;
     
    执行过程:
     
     
     
    结果分析:两张表进行union all 取相同的字段名称,可正常输出指定数据内容,且结果为两张表的结果集
     
    场景四:两张表在子查询中进行union 
     
    语句:
     
     select a.id,a.devid from (select a.id,a.devid,a.job_time from tb_in_base a union  select b.id,b.devid,b.job_time from tb_in_up b) a;
     
    执行过程:
     
     
     
    结果分析:hive 不支持union 
     
     
  • 相关阅读:
    python利用pip安装模块出现报错:ReadTimeoutError: HTTPSConnectionPool的解决方法
    20届一战南理工软件工程(专硕)824
    python—socket编程
    python—异常处理
    python—面向对象设计
    python—装饰器
    python—模块与包
    python—迭代器,生成器与for循环机制
    python—文件处理
    python—函数
  • 原文地址:https://www.cnblogs.com/fandelong/p/3922772.html
Copyright © 2011-2022 走看看