如何从hiveql中包含所有类别的双组中返回组

htzpubme  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(316)

我在hiveql中有这段代码,我只想返回同时具有女性和男性的组

select first_name, gender, count(*) from attributes  
group by first_name, gender

例如

name     gender   count
MICHAEL  FEMALE   10000
         MALE     11200

而不是:

name     gender   count
BILLY    MALE     12000
MARY     FEMALE   800
6qqygrtg

6qqygrtg1#

你可以用 having :

select first_name, count(*)
from attributes  
group by first_name
having min(gender) <> max(gender);
ldioqlga

ldioqlga2#

上面的代码是对的!只需要一行代码:

select first_name, gender ,count(*) from attributes  
 right join
 select first_name, count(*)
 from attributes  
 group by first_name
 having min(gender) <> max(gender);

相关问题