hive两张表实现like模糊匹配关联

sql 复制代码
testa表(字段a)
  aaa
  bba
  cccddd
  dddaaa

testb表(字段b)
   a
   b
   
1. 使用like+concat模糊配对
select
   a.a
from testa a ,testb b
where a like concat('%',b.b,'%')
group by a.a

2. 使用locate函数
select
   a.a
from testa a ,testb b
where locate(b.b,a.a)>0
group by a.a

3. 使用instr函数
select
   a.a
from testa a ,testb b
where instr(a.a,b.b)>0
group by a.a

3. 使用split函数
select
   a.a
from testa a ,testb b
where split(a.a,b.b)[1] is not null
group by a.a

注:

1.需要除重操作,比如:a表符合b两个将产生两条记录。

2.上面都会产生笛卡尔积,所以要注意数据量级。如果两个表都比较大,可以考虑将表拆分分别关联。

3.like效率比较低最好少用

相关推荐
鹿衔`4 小时前
Hadoop HDFS 核心机制与设计理念浅析文档
大数据·hadoop·hdfs
`林中水滴`5 小时前
数仓系列:一文读懂仓湖一体架构
数据仓库
Justice Young7 小时前
Sqoop复习笔记
hadoop·笔记·sqoop
大厂技术总监下海8 小时前
从Hadoop MapReduce到Apache Spark:一场由“磁盘”到“内存”的速度与范式革命
大数据·hadoop·spark·开源
zgl_200537799 小时前
ZGLanguage 解析SQL数据血缘 之 Python提取SQL表级血缘树信息
大数据·数据库·数据仓库·hive·hadoop·python·sql
Justice Young1 天前
Hive第四章:HIVE Operators and Functions
大数据·数据仓库·hive·hadoop
LF3_1 天前
hive,Relative path in absolute URI: ${system:user.name%7D 解决
数据仓库·hive·hadoop
德彪稳坐倒骑驴1 天前
Hive SQL常遗忘的命令
hive·hadoop·sql
Justice Young1 天前
Hive第六章:Hive Optimization and Miscellaneous
数据仓库·hive·hadoop
Justice Young1 天前
Hive第五章:Integeration with HBase
大数据·数据仓库·hive·hbase