Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hive 配置单元嵌套select语句_Hive_Hiveql - Fatal编程技术网

Hive 配置单元嵌套select语句

Hive 配置单元嵌套select语句,hive,hiveql,Hive,Hiveql,我正在尝试在配置单元中执行嵌套的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 我还尝试将select count(*)分配

我正在尝试在配置单元中执行嵌套的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
我还尝试将select count(*)分配给hivevar并在查询中使用它。但是,我还是遇到了同样的问题

set hivevar:cnt=select COUNT(*) as cnt from table2;
select col1, ${hivevar:cnt} , col2 from table1;

您可以对主表使用
WITH
子句和
交叉连接

WITH t AS (SELECT COUNT (*) AS ct FROM table2)
SELECT s.col1, t.ct, s.col2
  FROM table1 s CROSS JOIN t