HiveQL中的Insert命令中的多个查询

时间:2016-08-09 09:04:27

标签: hive hiveql

在我的用例中,我需要做这样的事情,

INSERT INTO TABLE test 
  select
      count(*) where recordedValue < 0,
      count(*) where recordedValue > 0 and recordedValue < 10,
      count(*) where recordedValue > 10 and recordedValue < 20
   from sample 

可以这样做吗?

1 个答案:

答案 0 :(得分:2)

INSERT INTO TABLE test 
select count(col1), count(col2), count(col3) From (
select 
CASE WHEN recordedValue < 0 THEN recordedValue END as col1,
CASE WHEN recordedValue > 0 AND recordedValue < 10 THEN recordedValue END as col2,
CASE WHEN recordedValue > 10 AND recordedValue < 20 THEN recordedValue END as col3 
from sample ) a;

首先检查select语句;