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

相关推荐
geovindu14 小时前
SQL Data Sampling and Approximation Techniques using postgreSQL 18
大数据·数据库·数据仓库·sql·postgresql·数据库开发·数据库架构
skywalk816316 小时前
hive —— 多机 AI Agent 协同的任务总线:分布式,多节点同时运行,保障不会宕机
人工智能·hive·分布式
程序员梅雨1 天前
【从零开始学习数据仓库 | 第一篇】:维度建模理论
大数据·数据仓库·学习·阿里云·数据分析
棣廷2 天前
初识数据仓库——数仓分层到DataX数据采集
数据仓库
棣廷2 天前
初识Hive(2)
数据仓库·hive·hadoop
skywalk81632 天前
deepseek对skywalk163/hive 和hivecommons/hive 两个多机AI Agent任务调度项目的对比
人工智能·hive·agent
father_12272 天前
【ambari管理下hdp2.6.5升级hive1.2.1-2.1.0-2.3.3】
hive·hadoop·ambari
geovindu3 天前
Pivoting and Unpivoting Data in SQL using postgreSQL 18
大数据·数据库·数据仓库·sql·postgresql·数据库开发·数据库架构
数据库小学妹3 天前
OLAP数据库怎么选?看清OLTP、数仓、湖仓边界
数据仓库·mpp·列式存储·联机分析处理·数据库选型·olap数据库