配置单元[错误10025]:表达式不在GROUP BY键名中

问题描述 投票:0回答:1

我正在尝试在一组变量中选择由关键词定义的记录。

name是一个具有关键术语的字符串。

组由id1和id2的组合定义。

我对按包含关键术语的组提取记录感兴趣。

select id1, id2, name
   case
    when name LIKE '%LOAD_TIME' then 1
    when name LIKE '%LOGIN_SESSION_TIME' then 1
   end as b_flag
   from df1
   group by id1, id2
   having (sum(b_flag) > 0 )

df1:

id1  id2  name                               
1     1    xxxLOAD_TIME
1     1    xxxLOGIN_LOGIN_SESSION_TIMExxx
1     1    xxxxSome other timexxxx
2     2    xxSome other timex
3     1    xxxLOAD_TIME
3     1    xxSome other timexx

创建b_flag之后,新的数据集应如下所示:

id1  id2  name                             b_flag   
1     1    xxxLOAD_TIME                      1
1     1    xxxLOGIN_LOGIN_SESSION_TIMExxx    1
1     1    xxxxSome other timexxxx   
2     2    xxSome other timex
3     1    xxxLOAD_TIME                      1
3     1    xxSome other timexx

所需的输出:

   id1  id2  name                             b_flag   
    1     1    xxxLOAD_TIME                      1
    1     1    xxxLOGIN_LOGIN_SESSION_TIMExxx    1
    1     1    xxxxSome other timexxxx   
    3     1    xxxLOAD_TIME                      1
    3     1    xxSome other timexx

我看不出我的代码有什么问题,但是我遇到了同样的错误:

[[错误10025]:表达式不在GROUP BY键名中

谢谢您的帮助

sql hive cloudera
1个回答
1
投票

您有要删除的真实重复项。对于您提供的数据集,我认为distinct足以产生预期的结果:

select distinct
    id1, 
    id2, 
    name
    case
        when name LIKE '%LOAD_TIME' then 1
        when name LIKE '%LOGIN_SESSION_TIME' then 1
   end as b_flag
   from df1 
© www.soinside.com 2019 - 2024. All rights reserved.