admin

SQL Hive子查询错误

sql

我有下面的查询

set hive.cli.print.header=true;
set hive.query.max.partition=1000;
set hive.mapred.mode=unstrict;

SELECT

dim_lookup("accounts",name,"account_id") = '28016' as company,
dim_lookup("campaigns",name,"campaign_id") in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215) as campaign_name,
case when is_click_through=0 then "PV" else "PC" end as conv_type,
(SELECT COUNT(1) FROM impressions WHERE ad_info[2] in (117649,112311,112319,112313,107799,110743,112559,112557,105191,105231,107377,108675,106587,107325,110671,107329,107181,106565,105123,106569,106579,110835,105127,105243,107185,105211,105215)) AS impressions

FROM actions

WHERE
data_date>='20170101'
AND data_date<='20171231'
AND conversion_action_id in (20769223,20769214,20769219,20764929,20764932,20764935,20769215,20769216,20764919,20769218,20769217,20769220,20769222)
GROUP BY conv_type

当我执行它时,我得到一个错误

 ERROR ql.Driver: FAILED: ParseException line 8:1 cannot recognize input near 'SELECT' 'COUNT' '(' in expression specification

我正在尝试获取指定的conversion_action_id的每次展示计数。我的查询中可能有什么错误?谢谢您的帮助。

仅供参考:ad_info [2]和campaign_id相同。


阅读 289

收藏
2021-07-01

共1个答案

admin

问题很明显,您在SELECT中有一个子查询。

这不是这样的。

不幸的是,确切的解决方案还不清楚,因为我不确定您想要什么,但是这里有一些一般性建议:

  1. 编写您的子查询,对其进行测试并确保它正常
  2. 而不是将其放在SELECT部分​​中,而是将其放在FROM部分中,并且(一如既往)将其从FROM中选择

只需将您的子查询输出视为可以在from语句中使用的其他表,并且需要将其与from语句中的其他表组合(JOIN,UNION?)。

2021-07-01