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效率比较低最好少用

相关推荐
技术小泽11 小时前
数开精讲chapter03:分析型引擎ClickHouse与Doris-StarRocks写入机制
数据仓库·后端·clickhouse·数据分析·infra
Nefu_lyh11 小时前
【Hadoop】02 详解HDFS中NameNode的工作机制与元数据管理
大数据·hadoop·hdfs
SeanQhl1 天前
Hadoop 单节点调优
hadoop·hdfs·性能调优·yarn·毕昇jdk
看浪的路人1 天前
第9讲:数据管道 Agent——从「ETL 脚本」到「自动化数据工厂」
数据仓库·自动化·etl
隔窗听雨眠1 天前
智能问数究竟替代了BI的哪一层
数据仓库·chatbi·商业智能
学编程就要猛2 天前
ETL(Extract Transform Load)
数据仓库·etl
衡石科技5 天前
二十多种数据源接进来:适配层、方言重写与 ETL 管道工程
数据仓库·etl·数据集成
skywalk81636 天前
lightharness第一次大规模开hive任务卡成功
人工智能·hive·agent·deepseek·lightharness
大今野7 天前
2026 专转本计算机|大数据关键技术:Hadoop、MapReduce、NoSQL 与处理流程(附例题)
大数据·hadoop·mapreduce·专转本
SeanQhl7 天前
鲲鹏开发套件综合实战
hadoop·性能调优·openeuler·鲲鹏devkit·应用迁移