以下命令在rdbms数据库上作为sql运行良好。但是,它无法在Hive上运行。
SELECT
entry_date,
customer,
cust_loc,
SUM(run_time) AS TOTAL_RUN,
SUM(CASE WHEN run_time BETWEEN 10000 AND 20000 THEN entry_date ELSE 0 END) AS SLOT_1,
SUM(CASE WHEN run_time BETWEEN 200001 AND 30000 THEN entry_date ELSE 0 END) AS SLOT_2,
SUM(CASE WHEN run_time BETWEEN 31000 AND 40000 THEN entry_date ELSE 0 END) AS SLOT_3
FROM
cust_run_details
WHERE
app_env IN ('a','b')
AND entry_date = '2015-02-01'
AND flag_set='U'
GROUP BY
customer,
customer,
cust_loc
在hive上运行时遇到的错误是
FAILED: SemanticException [Error 10016]: Line 6:80 Argument type mismatch '0': The expression after ELSE should have the same type as those after THEN: "string" is expected but "int" is found
我怎样才能把它转换成Hive当量?拜托,有什么主意能帮我吗
2条答案
按热度按时间n6lpvg4x1#
将sum改为count&去掉“else 0”。到那里花了很长时间。叹气。。
wz8daaqr2#
假设
entry_date
是一个date
,你可能不想sum()
是的。如果需要不同范围内运行时间的总和,则需要select
这样地:如果要计算不同范围内的运行时间,则:
如果
entry_date
可以是NULL
如果你想忽略这些记录,那么你可以包括and entry_date is not null
在WHEN
条件。