0

如何获得以下输出?

输入:

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

输出:

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

4 回答 4

2

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

SELECT row_number() OVER (ORDER BY a.col2) as col1, col2
FROM t1 a ORDER BY a.col2
于 2013-03-07T13:33:18.230 回答
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
于 2013-03-07T13:28:08.010 回答
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
于 2013-03-08T05:10:19.353 回答
0

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

SELECT * FROM t1 ORDER BY col1 ;

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

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

于 2013-03-07T13:38:35.530 回答