Home > OS >  Group by issue in Hive
Group by issue in Hive

Time:01-28

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

CodePudding user response:

Use max() and group by user_id:

select user_id, max(flag1) as flag1, max(flag2) as flag2
  from Tab1
 group by user_id;
  •  Tags:  
  • Related