zoukankan      html  css  js  c++  java
  • Hive非等值连接

    MySQL和Oracle都支持join...on...like的操作:

    SELECT *  
    FROM table1  
    LEFT JOIN table2  
    ON table1.xxx LIKE CONCAT('%',table2.yyy,'%') 

    在hive中要想使用非等值连接,可使用locate代替

    --LOCATE(a,b)功能就是寻找a在b中的位置,如果找到的话,返回位置;没找到的话,返回0。

    drop table if exists directory_index_project_belong;
    create table directory_index_project_belong
    as
    select
    a.id,    
    a.mac ,    
    a.file_md5,    
    a.directory_name,    
    a.directory_size,    
    a.directory_time,    
    a.directory_type,    
    a.directory_user,    
    a.directory_home,    
    a.directory_ftp ,    
    a.create_date ,    
    a.update_date ,    
    b.project_name as project_belong,    
    a.status
    from
    directory_index_distinct as a  left join directory_index_project b
    ON(TRUE)
    WHERE LOCATE(b.project_name,a.directory_home)>0 and LOCATE(b.project_name,a.directory_name)=0;

    上面的语句为b.project_name在a.directory_home中出现过且不在a.directory_name中出现过

    亲测left join 和directory_index_distinct表中数据不一致,只保留两表都有的数据,同join

  • 相关阅读:
    线程池进程池
    设计原则与设计模式
    腾讯阿里第三方接入
    计划任务
    系统服务
    Python Faker模块
    Python openpyxl模块
    Python-docx模块
    进程管理
    磁盘管理
  • 原文地址:https://www.cnblogs.com/qfdy123/p/14593354.html
Copyright © 2011-2022 走看看