Want to take the difference of two columns in Sql

前端 未结 2 2004
抹茶落季
抹茶落季 2021-01-24 18:31

I want to take the difference of columns of a table.we have column name as Planned_date so now I Want to take the difference of these two columns

A = Planned_Dat         


        
2条回答
  •  孤独总比滥情好
    2021-01-24 19:18

    Your query should work with a from clause:

    select (select planned_arrival as val1 
            from shipment_stop 
             where stop_num = 1 
             and shipment_gid = 'IFFCO/LOGISTICS.L171009358')
           -
          (select planned_arrival as val2 
           from shipment_stop 
           where stop_num = 5 
           and shipment_gid = 'IFFCO/LOGISTICS.L171009358')
    from dual;
    

    Personally, I would write this using conditional aggregation:

    select (max(case when stop_num = 1 then planned_arrival end) -
            max(case when stop_num = 5 then planned_arrival end)
           )
    from shipment_stop 
    where stop_num in (1, 5) and 
          shipment_gid = 'IFFCO/LOGISTICS.L171009358';
    

提交回复
热议问题