0

I have a table having a column event. It has data like IN and OUT.

Now I need to create two columns having the time of the first IN for a particular ID and the last OUT for the same ID.

I need to use partition by window function with lead and lag.

How can I do this?

Any help would be great!

I have to do this in HIVE!

4

1 回答 1

0

我假设您也有一些日期列(让我们称之为dt)。
要获得所有 ID 的第一个 IN 和最后一个 OUT,您需要执行以下操作:

select 
  id,
  min(case when event='IN' then dt end) first_in, 
  max(case when event='OUT' then dt end) last_out
from table
group by id
于 2014-08-26T12:26:38.790 回答