select * from (
select * from tab where a<2 and c=1 order by a) where rownum=1
没太明白你的意思
select * from tab where a<2 and c=1 order by a) where rownum=1
没太明白你的意思
解决方案 »
- 有人试过oracle Server 2008 (32-bit)1.9g xp能装不
- 菜鸟求PL-SQL语句
- 两段近似的SQL,执行情况却不大相同?
- 请教高技术
- 请问各位在前台pb中任何得到后台oracle中的表的个数
- 怎么查询一个数据库中有多少表?
- 关于BFile和JDBC的问题
- oracle的RAC模式下weblogic如何配置XA数据源
- windows 下 用mingw和oci怎么连接oracle 11g xe
- 请教:组内排序和组外排序的sql怎么写
- 小白求简略说明一下Oracle APEX 怎样进行开发?我想做一个和sample差不多的应用程序
- oracle11g的workflow的管理平台在哪儿?
(select 1 a, 2 b, 3 c
from dual
union all
select 2 a, 3 b, 1 c
from dual
union all
select 2 a, 4 b, 3 c
from dual
union all
select 2 a, 5 b, 1 c
from dual
union all
select 4 a, 6 b, 1 c
from dual)
select p_b
from (select t.*, lag(b) over(order by a) p_b, lag(c) over(order by a) p_c
from t) t1
where t1.a = 2
and p_c = 1;
lag(col,1,null) over(partition by col order by col)
lag函数是先分组再排序,并把当前行的上一个值放到该行中,lag(col,1,null)1表示增量字段,可以根据要求自定义,null是上一行不存在时用null代替,也可以自定义。
对于你的要求就不要分组了:
测试数据截图:select b
from (select a, lag(b) over(order by a) b, lag(c) over(order by a) c
from my_test) t
where t.a = 2
and t.c = 1;
测试结果: