Piyush Chandra
Piyush Chandra

Reputation: 23

Group by issue in Hive

I have table having three field Tab1(user_id,flag1,flag2). sample data:

user_id    Flag1     Flag2
10001       0          1 
10001       1          0
10001       0          1
10002       1          0
10002       0          1 

How to get output as:

User_id.   Flag1.     Flag2
10001       1         1
10002       1         1

Upvotes: 1

Views: 29

Answers (1)

leftjoin
leftjoin

Reputation: 38290

Use max() and group by user_id:

select user_id, max(flag1) as flag1, max(flag2) as flag2
  from Tab1
 group by user_id;

Upvotes: 1

Related Questions