hivesql-erorr不匹配的输入“as”应为

92dk7w1h  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(350)

我有一些这样的代码。我想按分区(月)和数据使用量(g.volumn)计算电话号码(isdn)的数量

select partition,
    case when a.g_volume = 0 then '0MB'
         when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
         when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
    end as data,
    count(distinct a.isdn) as num_isdn
from 
    (select partition, g_volume, sub_type, infras, num_register_day, isdn
    from f121_tot_charge_accum_final
    where partition in ('2020101','2020102','2020103','2020104')) a
group by partition, 
    case when a.g_volume = 0 then '0MB'
         when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
         when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
    end as data;

但是sql说这样的错误


**Query execution failed

Reason:
SQL Error: org.apache.spark.sql.catalyst.parser.ParseException: 
mismatched input 'as' expecting {<EOF>, ',', '.', '[', 'GROUPING', 'ORDER', 'HAVING', 'LIMIT', 'OR', 'AND', 'IN', NOT, 'BETWEEN', 'LIKE', RLIKE, 'IS', 'WINDOW', 'WITH', 'UNION', 'EXCEPT', 'INTERSECT', EQ, '<=>', '<>', '!=', '<', LTE, '>', GTE, '+', '-', '*', '/', '%', 'DIV', '&', '|', '^', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(line 15, pos 5)**

有人能帮帮我吗。我不明白为什么。

dm7nw8vv

dm7nw8vv1#

您的分组依据具有列别名定义:

case when a.g_volume = 0 then '0MB'
     when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
     when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
end as data;
----^

你得把这个取下来。列别名只能在 select :

group by partition, 
    case when a.g_volume = 0 then '0MB'
         when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
         when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
    end ;

也就是说,我认为Hive可以允许在 group by :

group by 1, 2;

相关问题