I have a hive table with IDs and associated events that look like below. The table can have multiple event_number for the same ID -
ID event_number Date
ABC 1 2022-08-01
ABC 2 2022-08-01
ABC 3 2022-08-01
DEF 1 2022-08-01
GHI 2 2022-08-02
DEF 3 2022-08-01
I want to find unique ids that have events 1 and 2 in a day
- Here the output would be ABC because that is the only ID with both event 1 and event 2 for a given date.
- It cannot be DEF or GHI since they either have event 1 or 2
Here is the query I came up for this -
select distinct ID from table where event_number=1 and date=2022-08-01
and ID in( Select ID from table where event_number=2 and date=2022-08-01);
Is there a more elegant or efficient way to do this?