Hive SQL:Select 事件前的所有行
Hive SQL: Select all rows before event
在 Hive 中,我有以下数据
sess,person,type,number
a mary I 1
a mary I 2
a mary V 3
a mary V 4
b mary I 1
b mary V 2
b mary C 3
a john I 1
a john I 2
a john V 3
a john V 4
b john I 1
b john V 2
b john C 3
如何 select 每个人和会话的所有内容,包括第一个 type=V?输出应该看起来像
sess,person,type,number
a mary I 1
a mary I 2
a mary V 3
b mary I 1
b mary V 2
a john I 1
a john I 2
a john V 3
b john I 1
b john V 2
您可以使用 window 函数:
select t.*
from (select t.*,
min(case when type = 'V' then number end) over (partition by session, person order by number) as min_aid
from t
) t
where min_aid is null or number <= aid;
在 Hive 中,我有以下数据
sess,person,type,number
a mary I 1
a mary I 2
a mary V 3
a mary V 4
b mary I 1
b mary V 2
b mary C 3
a john I 1
a john I 2
a john V 3
a john V 4
b john I 1
b john V 2
b john C 3
如何 select 每个人和会话的所有内容,包括第一个 type=V?输出应该看起来像
sess,person,type,number
a mary I 1
a mary I 2
a mary V 3
b mary I 1
b mary V 2
a john I 1
a john I 2
a john V 3
b john I 1
b john V 2
您可以使用 window 函数:
select t.*
from (select t.*,
min(case when type = 'V' then number end) over (partition by session, person order by number) as min_aid
from t
) t
where min_aid is null or number <= aid;