pgsql的一句经典代码

select mp3.* from (

select distinct (t1.flight_number) as flight_number1,items.* from guarantee_node t1
left join LATERAL (
select * from guarantee_node gn where t1.flight_number=gn.flight_number
order by guarantee_time desc limit 1

) AS items ON true

union all

select distinct (t1.flight_number) as flight_number,items.* from guarantee_node t1
left join LATERAL (
select * from guarantee_node gn where t1.flight_number=gn.flight_number
order by guarantee_time asc limit 1

) AS items ON true
) mp3
where


mp3.flight_number1 in (
select flight_number from guarantee_node where
guarantee_type='航空器离位'
)


order by mp3.flight_number1 asc ,guarantee_time desc

posted on 2023-08-31 11:23  漫思  阅读(8)  评论(0编辑  收藏  举报

导航