当前位置: 动力学知识库 > 问答 > 编程问答 >

Case-When table name in Hive

问题描述:

How can I CASE WHEN table name in a Hive SELECT query?

I want to do something to the effect of -

SELECT col1, col2

FROM

CASE ${PARAM}

WHEN 'val1' THEN table1

WHEN 'val2' THEN table2

网友答案:

This is possible. Rewrite your query like this:

SELECT col1, col2 FROM table1 WHERE '${PARAM}' = 'val1' --only one subquery will be executed
union all
SELECT col1, col2 FROM table2 WHERE '${PARAM}' = 'val2' 
分享给朋友:
您可能感兴趣的文章:
随机阅读: