【发布时间】:2019-10-25 07:47:23
【问题描述】:
我有一个场景,例如:
with tmp as (select name from table1)
select * from table2 b
where b.name=(select max(name) from tmp)
但是,Hive 无法识别这种语法,那么是否有任何合法的语法呢?
经过搜索得知可以使用join实现:
select table2.* from table2
join (select max(name) as name from tmp) t2
where table2.name = t2.name
但我不想使用join,因为join会很慢,我只是想作为参考。
就像在MySQL 中一样,您可以将结果设置为参考:
set @max_date := select max(date) from some_table;
select * from some_other_table where date > @max_date;
而Hive可以达到将查询结果存储在shell的效果。检查:HiveQL: Using query results as variables
Hive 可以在 SQL 模式下支持这样的功能吗?
【问题讨论】:
-
加入不会慢子查询很慢