deb
deb

Reputation: 29

Hive how to combine multiple records within a group based on condition

i have dataset as following.

client-Id   Name    HasCar     HasHome
A01          ABC      Y          N
A01          ABC      N          N
B01          EFG      N          N
B01          EFG      N          Y

From here I need to derive a Single row for each customer whether he has car or home. the expected output should look like below

Client-Id    Name    HasCar     HasHome
A01          ABC      Y          N
B01          EFG      N          Y

This needs to be done using a Hive-QL

Upvotes: 1

Views: 110

Answers (1)

leftjoin
leftjoin

Reputation: 38335

Use max() aggregation:

select client-Id,Name, max(HasCar) HasCar,  max(HasHome) HasHome
  from your_table 
 group by client-Id,Name

Upvotes: 1

Related Questions