Hive with clause和join语句

时间:2018-03-14 13:22:23

标签: sql hive common-table-expression

我有以下查询,我正在尝试加入两个分组列的语句。

.*

我收到的错误是无法识别内部'内部的输入。 '加盟' ('声明

1 个答案:

答案 0 :(得分:1)

不确定您要执行的操作,但cte后面应该是另一个cte或selectinsert

您可以使用

select name, title,
  max(case when special = 'super' then max_power end) as Super_max,
  max(case when special = 'awesome' then max_power end) as Awesome_max,
  min(case when special = 'super' then max_power end) as Super_min,
  min(case when special = 'awesome' then max_power end) as Awesome_min
from mytable
group by name, title

如果列名必须相同,请使用union all

select name, title,
  max(case when special = 'super' then max_power end) as Super,
  max(case when special = 'awesome' then max_power end) as Awesome
from mytable
group by name, title
union all
select name, title,
  min(case when special = 'super' then max_power end) as Super,
  min(case when special = 'awesome' then max_power end) as Awesome
from mytable
group by name, title