不好意思,看错了,不用子查询可以这样: select first_value(B) over(order by a desc) from table where a<=3
如果你是oracle9i就有,是分析函数
应该是这样: select distinct first_value(B) over(order by a desc) from table where a<=3
1. 定义一个表得到结果 A B C 1 b1 1 2 b2 2 3 4 b4 4 5 6 7 b7 7 建立C表 一个字段C 1 2 3 4 5 6 7........ 建立表tab_c create table tab_c as select * from c, table_you where c.c=table_you.a(+) order by c; 得到上面的表 2。 select decode (b, null, (select b from tab_c where c=( select max(a) from tab_c where c<c)), b) from tab_c where c=3
select B from table_name where A = (select 6- min(6-A) from table_name where A <= 6 )
select b from table where a = (select max(a) from table where a<=6);
无风的简洁 ,但是要考虑多行数值情况: select b from table where a in (select max(a) from table where a<=6);
sorry ,我说的有误,无风的正确: select b from table where a = (select max(a) from table where a<=6);
select first_value(B) over(order by a desc) from table where a<=3
select distinct first_value(B) over(order by a desc) from table where a<=3
A B C
1 b1 1
2 b2 2
3
4 b4 4
5
6
7 b7 7
建立C表 一个字段C 1 2 3 4 5 6 7........
建立表tab_c
create table tab_c as
select * from c, table_you
where c.c=table_you.a(+)
order by c;
得到上面的表
2。 select decode (b, null, (select b from tab_c where c=(
select max(a) from tab_c where c<c)), b)
from tab_c
where c=3
A =
(select 6- min(6-A) from table_name where A <= 6 )
select b from table where a in (select max(a) from table where a<=6);
select b from table where a = (select max(a) from table where a<=6);