日期:2014-05-17  浏览次数:20802 次

请一个sql语句
oracle实现如下效果

表 a

id name

1 a

2 b

3 c

4 d


需要结果集为


id name  

1 b

2 c

3 d

4 a

有好的写法不

------解决方案--------------------
这个结果是怎么出来的,大姐,解释一下行不!!
------解决方案--------------------
测试数据:
SQL code

CREATE TABLE T190
(
    ID NUMBER(4),
    F1 VARCHAR2(20)
);

INSERT INTO T190 VALUES(1, 'a');
INSERT INTO T190 VALUES(2, 'b');
INSERT INTO T190 VALUES(3, 'c');
INSERT INTO T190 VALUES(4, 'd');

------解决方案--------------------
估计楼主是想要分析函数的效果
lag() over 和lead() over()
------解决方案--------------------
SQL code

with t as(
select 1 id, 'a' name from dual
union all
select 2,'b' from dual
union all
select 3,'c' from dual
union all
select 4,'d' from dual
)select id,name from t order by mod(id,4)
        ID NAME
---------- ----
         4 d
         1 a
         2 b
         3 c

------解决方案--------------------
SQL code

with t as(
select 1 id, 'a' name from dual
union all
select 2,'b' from dual
union all
select 3,'c' from dual
union all
select 4,'d' from dual
)select id,name from t order by mod(id+2,4)
        ID NAME
---------- ----
         2 b
         3 c
         4 d
         1 a

------解决方案--------------------
SQL code

with t as(
select 1 id, 'a' name from dual
union all
select 2,'b' from dual
union all
select 3,'c' from dual
union all
select 4,'d' from dual
)select mod(id+2,4)+1 id,name from t order by id        ID NAME
---------- ----
         1 b
         2 c
         3 d
         4 a