简体   繁体   English

SQL to Hive查询语法

[英]SQL to Hive query syntax

How can I turn the below SQL to Hive query? 如何将下面的SQL转换为Hive查询? I get an error FAILED: ParseException line 2:31 cannot recognize input near 'select' 't2' '.' in expression specification 我收到错误FAILED: ParseException line 2:31 cannot recognize input near 'select' 't2' '.' in expression specification FAILED: ParseException line 2:31 cannot recognize input near 'select' 't2' '.' in expression specification

select ip,
       sum(case when score <> (select t2.score from score t2
                               where t2.timestamp = (select max(timestamp) from score
                                                     where ip = t2.ip
                                                       and timestamp < t1.timestamp)
                                 and t1.ip = t2.ip) then 1 else 0 end)
from score t1
group by ip;

Hive does not support subqueries in case statements AFAIK. Hive不支持case语句AFAIK的子查询。 You could restructure this to an outer query (atill using case) from an inline view. 您可以从内联视图将其重组为一个外部查询(使用用例)。

select ip, sum(case when score <> s.score) ..
from (select  t2.score ..) s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM