select col_num from table where ...
union
selcct last_value(col_num) over(order by rownum)-first_value(col_num) over(order by rownum) from table where ... and rownum=1;

解决方案 »

  1.   

    sorry,用union all比较合适
    select col_num from table where ...
    union all
    selcct last_value(col_num) over()-first_value(col_num) over() from table where ... and rownum=1;
      

  2.   

    谢谢
    还想更进一步的请教一下,可否不用union来实现?
    因为我是要选出很多值,而那个差值只是其中之一,而且我已经用了union,也就是说其实我的情况是:
    select value1,value2,value3 from table1 where....union select value4,value5 from table2 where...
    而value2就是我想要的差值(2-5=3),也就是beckhambobo兄提供的那个结果
      

  3.   

    是不是这样
    [email protected]>select id,last_value(id)over()-first_value(id)over() result from num_table;        ID     RESULT
    ---------- ----------
             5         -3
             4         -3
            63         -3
            52         -3
             2         -3
            15         -3
             4         -3
             2         -3已选择8行。
      

  4.   

    select value1,last(value1) over()-first(value1) over() value2,value3 from 
    (select value1,value3 from table1 where....
    union 
    select value4,value5 from table2 where...)
      

  5.   

    select value1,last(value1) over()-first(value1) over() value2,value3 from 
    (select value1,value3 from table1 where....
    union 
    select value4,value5 from table2 where...)
      

  6.   

    呵呵,笔误
    last(value1) over()-first(value1) over() value2

    last_value(value1) over()-first_value(value1) over() value2
      

  7.   

    more_zou兄的解答中,id是不能显示出来的,因为我得把这段语句用在程序中,不能给别人看id值