我正在尝试在Hive中执行嵌套的select语句 -
select col1, (select COUNT(*) as cnt from table2) , col2 from table1;
当我在上面运行查询时,我遇到了异常 -
FAILED: ParseException line 1:8 cannot recognize input near 'select' 'COUNT' '(' in expression specification
我还尝试将选择计数(*)分配给hivevar并在查询中使用它。但是,我仍然遇到同样的问题。
set hivevar:cnt=select COUNT(*) as cnt from table2;
select col1, ${hivevar:cnt} , col2 from table1;
答案 0 :(得分:1)
您可以在主表中使用WITH
子句和CROSS JOIN
。
WITH t AS (SELECT COUNT (*) AS ct FROM table2)
SELECT s.col1, t.ct, s.col2
FROM table1 s CROSS JOIN t