我有一个数据集
,如下例所示。
id,start_location,start_time,end_location,end_time
1P18UA,A,15/06/2020 05:48,B,15/06/2020 05:58
1P18UA,B,15/06/2020 05:59,C,15/06/2020 06:30
1P18UA,C,15/06/2020 06:32,D,15/06/2020 06:55
1P18UA,D,15/06/2020 06:57,E,15/06/2020 07:20
我希望创建一个视图,该视图显示每个记录补丁的单行,例如
id,start_location,start_time,end_location,end_time
1P18UA,A,15/06/2020 05:48,E,15/06/2020 07:20
即显示批处理中第一行的开始时间和位置以及同一批处理中最后一行的结束位置和时间。
您可以尝试下面的查询。
select a.id, a.start_location, b.start_time, a.end_location, b.end_time
from tbl a join (
select id, min(start_time) start_time, max(end_time) end_time
from tbl group by id
) b on a.id = b.id
and a.start_time = b.start_time
and a.end_time = b.end_time