Hive does not support such subqueries and also does not allow to calculate a variable, variables in Hive are simple text substitution without calculation. You can calculate predicate in a shell and pass to your hive script like in this answer: https://stackoverflow.com/a/37821218/2700344
If you want to do it in the same hive query, nothing wrong in calculating subquery and do a cross join with it's result, then filter. subquery will be calculated first, then it's result placed in the distributed cache and applied in the filter in each mapper reading the table:
with sub as(--this is example only and makes no sense
--replace with real query
--of course there is no rows with sal>max sal in the same table
select max(S.sal) AS MaxSal from employee S
)
select *
from employee e
cross join sub s
where e.sal>s.MaxSal
If you write it without CROSS JOIN
, simply from employee e, sub s
, or JOIN without on condition, it is still the same cross join, better write it explicitly using cross join.