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;
union
selcct last_value(col_num) over(order by rownum)-first_value(col_num) over(order by rownum) from table where ... and rownum=1;
解决方案 »
- "Global Cache Blocks Lost" 位于9
- 请叫一个Oracle问题
- 重分悬赏!Oracle,Spool 不会用,无法写批处理删除用户的会话session!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 非常怪异的SQL语句
- 有一万条数据需要插入数据库,各位高手给点提示吧
- 请教高手 我建的触发器出错:PLS-00103 请帮帮忙!
- oracle 里面的很多用户一开始就是expired,怎样能变成可用状态
- Oracle在安装后,字符集可否进行更改(版本8.0.5)?
- ORACLESERVER(SID)已启用
- 各位帮我看看,这种IN语句怎么优化??
- 怎么安装oraoledb.oracle
- sql*plus中可有直接看表的命令?
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;
还想更进一步的请教一下,可否不用union来实现?
因为我是要选出很多值,而那个差值只是其中之一,而且我已经用了union,也就是说其实我的情况是:
select value1,value2,value3 from table1 where....union select value4,value5 from table2 where...
而value2就是我想要的差值(2-5=3),也就是beckhambobo兄提供的那个结果
[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行。
(select value1,value3 from table1 where....
union
select value4,value5 from table2 where...)
(select value1,value3 from table1 where....
union
select value4,value5 from table2 where...)
last(value1) over()-first(value1) over() value2
改
last_value(value1) over()-first_value(value1) over() value2