一个飞机执行航班的表:flight,如下
PLANE_NO  FLIGHT_NO   TIME
B2153     7323        07:00
B2456     2160        08:40
B3423     529         08:10
B2153     2335        10:00
B3423     528         11:30如上表所示,一架飞机可能会执行多个航班,
现在需要将飞机号按照该飞机最早执行的航班的起飞时间排序,如上表,查询结果应该如下:PLANE_NO   TIME
B2153      07:00
B3423      08:10
B2456      08:40请问这个结果的SQL该如何写呢?

解决方案 »

  1.   

    select plane_no,min(time) from fight group by  plane_no order by min(time);
      

  2.   

    select PLANE_NO, min(time) keep(dense_rank first order by time)
      from fight
     group by PLANE_NO;
      

  3.   

    select plane_no,time from
    (select plane_no,time,row_number() over(partition by plane_no order by time) rn from test2) a
    where a.rn=1;