无法识别子查询中“select”附近的输入

时间:2016-09-05 17:38:33

标签: sql database hadoop hive

SELECT 
    (case TRIM(T.tactictype)
        WHEN  'Economics' THEN
            (select economic_tactic_id from cfext.economic_tactics E where LOWER(E.economic_tactic_name) = LOWER(T.tacticname) )
        WHEN  'Cyber' THEN
            (select cyber_tactic_id from cfext.cyber_tactics E where LOWER(E.cyber_tactic_name) = LOWER(T.tacticname) )
    end) AS tacticid 
FROM cfext.banking_crreport_allfiles T
LIMIT 50;

我正在尝试运行上面的查询,错误如下。 任何人都可以帮忙。

FAILED:ParseException第4:1行无法识别'select''economic_tactic_id''附近的输入来自'表达式规范

3 个答案:

答案 0 :(得分:0)

尝试使用

SELECT (case TRIM(T.tactictype) WHEN 'Economics' THEN (select E.economic_tactic_id from cfext.economic_tactics E 
    where LOWER(E.economic_tactic_name) = LOWER(T.tacticname) ) 
WHEN 'Cyber' THEN (select E.cyber_tactic_id from cfext.cyber_tactics E where LOWER(E.cyber_tactic_name) = LOWER(T.tacticname) ) end) AS tacticid 
FROM cfext.banking_crreport_allfiles T LIMIT 50;

答案 1 :(得分:0)

SELECT (case TRIM(T.tactictype)
     WHEN 'Economics' THEN
      (select et.economic_tactic_id
         from cfext.economic_tactics et
        where LOWER(et.economic_tactic_name) = LOWER(T.tacticname))
     WHEN 'Cyber' THEN
      (select e.cyber_tactic_id
         from cfext.cyber_tactics e
        where LOWER(e.cyber_tactic_name) = LOWER(T.tacticname))
   end) AS tacticid`enter code here` FROM cfext.banking_crreport_allfiles T LIMIT 50;

答案 2 :(得分:0)

Hive不支持SELECT子句中的子查询。你需要改写逻辑:

SELECT COALESCE(E.economic_tactic_id, C.cyber_tactic_id) as tacticid 
FROM cfext.banking_crreport_allfiles T LEFT JOIN
     cfext.economic_tactics E 
     ON LOWER(E.economic_tactic_name) = LOWER(T.tacticname) AND
        TRIM(T.tactictype) = 'Economics' LEFT JOIN
     cfext.cyber_tactics C
     ON LOWER(C.cyber_tactic_name) = LOWER(T.tacticname) AND
        TRIM(T.tactictype) = 'Cyber';