先问下:
比如取A=6的时候,你是取比a小的那条吗,取到的是b3,即A=4的时候值;如果离6最近是7对吗,应该是b4

解决方案 »

  1.   

    不好意思,看错了,不用子查询可以这样:
    select first_value(B) over(order by a desc) from table where a<=3
      

  2.   

    如果你是oracle9i就有,是分析函数
      

  3.   

    应该是这样:
    select distinct first_value(B) over(order by a desc) from table where a<=3
      

  4.   

    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
       
      

  5.   

    select  B from table_name where 
        A = 
         (select 6- min(6-A) from table_name   where A <= 6  )
      

  6.   

    select b from table where a = (select max(a) from table where a<=6);
      

  7.   

    无风的简洁 ,但是要考虑多行数值情况:
    select b from table where a in (select max(a) from table where a<=6);
      

  8.   

    sorry ,我说的有误,无风的正确: 
    select b from table where a = (select max(a) from table where a<=6);