查询重复值并选择与之对应的列值

时间:2019-01-30 08:20:30

标签: select hive duplicates

enter image description here

我需要从表TEST中提取数字,该表具有两种以上的区域类型,并且区域=“ three”作为值。我应该得到结果“ b”和“ f”。

谢谢。

1 个答案:

答案 0 :(得分:0)

以下是查询-

select count(*), number from <tableName> where number in (select number from <tableName> where area='three') group by number having count(*)>1;

select number from <tableName> group by number having count(*)>1 and sum(case when area='Three' then 1 else 0) = 1;