t1表:
order_id order_type order_time
111 N 10:00
111 A 10:05
111 B 10:10
是用hql获取结果如下:
order_id order_type_1 order_type_2 order_time_1 order_time_2
111 N A 10:00 10:05
111 A B 10:05 10:10
观察发现order_type_1,order_time_1就是第一行的数据和第二行的数据,order_type_2,order_time_2就是第二行的数据和第三行的数据
select
*
from
(select
order_id,
order_type order_type_1,
lead(order_type) over(partition by order_id order by order_time) order_type_2,
order_time order_time_1,
lead(order_time) over(partition by order_id order by order_time) order_time_2
from
t1) t2
where order_time_2 is not null
;