在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
如何为第一个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
发布于 2018-08-06 17:20:17
您可以使用窗口函数:
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;
https://stackoverflow.com/questions/51712519
复制相似问题