Search code examples
hiveqlhue

How to find the earlier date between two events?


I have the following table:

enter image description here

For each member from this table, I would like to get the event date. The event date should be pulled by comparing the event dates for "run" and 'jog" events and which ever date is smaller/earlier, that date is what i need.

So my output table will look like:

enter image description here


Solution

  • Assuming event_date is of date type or at least a string in YYYY-MM-DD format (and it was changed in the Excel)

    select      member
               ,min(event_date)
    from        mytable
    where       event in ('run','jog')
    group by    member