繁体   English   中英

如何获得以下输出?

[英]How to get the following output?

如何获得以下输出?

输入:

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

输出:

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

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

SELECT row_number() OVER (ORDER BY a.col2) as col1, col2
FROM t1 a ORDER BY a.col2
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

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

SELECT * FROM t1 ORDER BY col1 ;

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

http://www.sqlfiddle.com/#!3/2e3e9/1/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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM