私はこれに苦労してきました。左外部結合、グループ化、さらにはサブクエリなどのすべてのアプローチを試しましたが、成功しませんでした。これが私のクエリです。
select star_ident,transition_ident,fix_ident,sequence_num,route_type
from corept.std_star_leg where data_supplier='J' and airport_ident='KMMU';
上記の結果セットから、指定された transition_ident および star_ident に対して最大の sequence_num を持つ行を抽出する必要があります。これが私のクエリです。
select star_ident,transition_ident,fix_ident,max(sequence_num)
from corept.std_star_leg where data_supplier='J' and airport_ident='KMMU'
group by transition_ident,star_ident;
しかし、上記のクエリは間違った結果を生成しています.私も結合を試みました.
select yt1.star_ident,yt1.transition_ident,yt1.fix_ident
from corept.std_star_leg yt1
left outer join corept.std_star_leg yt2
on (yt1.star_ident = yt2.star_ident and yt1.transition_ident=yt2.transition_ident and yt1.sequence_num < yt2.sequence_num)
where yt1.airport_ident='KMMU' and yt1.data_supplier='J'
and yt2.airport_ident='KMMU' and yt2.data_supplier='J' and yt2.star_ident is null;
しかし、私は行がゼロになります.これを行う効率的な方法を教えてください.13Kのエントリに対してこのクエリを実行する必要があります.ありがとう.