1
group by
をセグメント単位で実行する必要があります。下の例では、4つの「グループ」があり、旅の脚線を表しています。SQL Server:GROUP BY類似の一致する行の複数のセグメント
SELECT id, mode, distance
FROM TravelLog;
出力:
-----------------------------------------------------------------------------
id mode distance
-----------------------------------------------------------------------------
1 on_foot 0.1
2 on_foot 0.2
3 on_foot 0.4
4 on_foot 0.6
5 on_foot 0.7
6 on_foot 0.8
7 in_vehicle 0.9
8 in_vehicle 2.0
9 in_vehicle 2.5
10 in_vehicle 3.0
11 in_vehicle 3.5
12 in_vehicle 4.0
13 in_vehicle 4.5
14 on_foot 4.6
15 on_foot 4.7
16 on_foot 4.8
17 on_foot 4.9
18 in_vehicle 5.5
19 in_vehicle 6.0
20 in_vehicle 6.5
-----------------------------------------------------------------------------
望ましい結果:あなたは、隣接する "モード" のグループを識別するために必要
-----------------------------------------------------------------------------
start_id end_id start_distance end_distance mode
-----------------------------------------------------------------------------
1 6 0.1 0.8 on_foot
7 13 0.9 4.5 in_vehicle
14 17 4.6 4.9 on_foot
18 20 5.5 6.5 in_vehicle
-----------------------------------------------------------------------------
これは完全に機能します。そして、あなたが答えるよりも、質問を書くのに時間がかかりました!ありがとうございました! – gunwin