假设下表:
Action, Action_Timestamp
act_b 1
act_a 2
act_x 3
act_b 4
act_c 6
act_b 7
act_c 8
我想知道是否存在这样的行动序列(在他们之间采取行动):
`act_a -> act_b -> act_c` where `act_a_timestamp < act_b_timestamp < act_b_timestamp` (aka first occurrence of each event)
所以结果应该是这样的:
Action, Action_Timestamp
act_a 2
act_b 4
act_c 6
请您帮我编写SQL查询以获得上面显示的结果?
P.S。我的RDBMS
中没有限制答案 0 :(得分:2)
您没有说明您的DBMS,因此这是标准的SQL:
select action, action_timestamp
from (
select action, action_timestamp,
row_number() over (partition by action order by action_timestamp) as rn
from the_table
) t
where rn = 1;