案例 - 当Hive中的表名时

时间:2017-01-11 01:31:31

标签: hive

如何在Hive SELECT查询中对表名称进行CASE?

我想做点什么 -

SELECT col1, col2 
FROM
  CASE ${PARAM}
    WHEN 'val1' THEN table1
    WHEN 'val2' THEN table2

1 个答案:

答案 0 :(得分:1)

这是可能的。像这样重写你的查询:

SELECT col1, col2 FROM table1 WHERE '${PARAM}' = 'val1' --only one subquery will be executed
union all
SELECT col1, col2 FROM table2 WHERE '${PARAM}' = 'val2'