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

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

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

  1. select partition,
  2. case when a.g_volume = 0 then '0MB'
  3. when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
  4. when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
  5. end as data,
  6. count(distinct a.isdn) as num_isdn
  7. from
  8. (select partition, g_volume, sub_type, infras, num_register_day, isdn
  9. from f121_tot_charge_accum_final
  10. where partition in ('2020101','2020102','2020103','2020104')) a
  11. group by partition,
  12. case when a.g_volume = 0 then '0MB'
  13. when a.g_volume <=10 and a.g_volume > 0 then '0-10MB'
  14. when a.g_volume <=50 and a.g_volume >10 then '10 - 50MB'
  15. end as data;

但是sql说这样的错误

  1. **Query execution failed
  2. Reason:
  3. SQL Error: org.apache.spark.sql.catalyst.parser.ParseException:
  4. 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#

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

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

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

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

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

  1. group by 1, 2;
展开查看全部

相关问题