我一直在为此苦苦挣扎。我尝试了所有方法,例如左外连接、分组方式甚至子查询,但都没有成功。这是我的查询。
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 条目运行此查询。谢谢。