如何获得以下输出?

时间:2013-03-07 13:06:20

标签: sql oracle

如何获得以下输出?

输入:

t1
-----------------
col1    col2
----------------
2        a
1        c
3        b
----------------

输出:

t1
-----------------
col1        col2
----------------
1           a
2           b
3           c
----------------

4 个答案:

答案 0 :(得分:2)

您可以尝试使用行号,如:

SELECT row_number() OVER (ORDER BY a.col2) as col1, col2
FROM t1 a ORDER BY a.col2

答案 1 :(得分:1)

select  C1.col1, C2.col2
from
  (select col1, row_number() over (order by col1) rn
  from t1) C1
join 
  (select col2, row_number() over (order by col2) rn
  from t1) C2
on C1.rn=C2.rn
order by C1.rn

答案 2 :(得分:0)

我认为以下查询可能对您有帮助。

SELECT * FROM t1 ORDER BY col1 ;

请查看此链接以获取更多练习

http://www.sqlfiddle.com/#!3/2e3e9/1/0

答案 3 :(得分:0)

试试这个..

select col1,col2 from
(select col1,rownum rn from(select col1 from t1 order by col1)) a,
(select col2,rownum rn from(select col2 from t1 order by col2)) b
where a.rn=b.rn