try:
select * from (
select row_number() over(order by gxsj) no,tbname.* from tbname 
) t1
(select no from (
select row_number() over(order by gxsj) no,tbname.* from tbname 
) t where id='0604') t2
where abs(t1.no-t2.no)<2;

解决方案 »

  1.   

    http://download.oracle.com/docs/cds/B19306_01.zip
    oracle 10g全文档
      

  2.   

    select * from (
    select row_number() over(order by gxsj) no,tbname.* from tbname 
    ) t1,
    (select no from (
    select row_number() over(order by gxsj) no,tbname.* from tbname 
    ) t where id='0604') t2
    where abs(t1.no-t2.no)<2;
    楼上正解
      

  3.   

    with t as (select *,rownum rn from table order by gxsj)
    select id,
          gxsj,
          name,
          value
    from  t
    where t.rn >= ( select rn - 1 from t where t.id = '0604')
     and t.rn <= ( select rn + 1 from t where t.id = '0604')
      

  4.   

    WITH t1 AS
         (SELECT ROWNUM rn
            FROM (SELECT   *
                      FROM table
                  ORDER BY gxsj)),
         t2 AS
         (SELECT rn
            FROM (SELECT ROWNUM rn, id
                    FROM (SELECT   *
                              FROM table
                          ORDER BY gxsj))
           WHERE id = '0604')
    SELECT id,gxsj,name,value
      FROM t1
     WHERE rn < (SELECT rn + 2 FROM t2)
       AND rn > (SELECT rn - 2 FROM t2);
      

  5.   

    收藏,学习厉害,sql的学问还真不少啊,以上几个方法的sql我都试过,没问题
      

  6.   

    我还要加其他的where条件,应该加在哪啊?
      

  7.   

    NO ID         GXSJ                 NAME                 VALUE                        NO
    ---------- ---------- -------------------- -------------------- -------------------- ----------
             3 0023       2006-8-1 18:12:25    name3                value3                        4
             4 0604       2006-8-1 18:12:25    name4                value4                        4
             5 0405       2006-8-1 18:12:26    name5                value5                        4
      

  8.   

    NO是按GXSJ排序的编号,
    你可以将最外层的*替换成你需要的列名NO ID GXSJ NAME VALUE
      

  9.   

    支持大斑竹bzszp(SongZip)select * from (
    select row_number() over(order by gxsj) no,tbname.* from tbname
    ) t1
    (select no from (
    select row_number() over(order by gxsj) no,tbname.* from tbname
    ) t where id='0604') t2
    where abs(t1.no-t2.no)<2;