Create table If Not Exists Data (first_col int, second_col int)
Truncate table Data
insert into Data (first_col, second_col) values ('4', '2')
insert into Data (first_col, second_col) values ('2', '3')
insert into Data (first_col, second_col) values ('3', '1')
insert into Data (first_col, second_col) values ('1', '4');
分析数据
a表
sql复制代码
select row_number() over(order by first_col) as id, first_col
from Data
b表
sql复制代码
select row_number() over(order by second_col desc) as id, second_col
from Data
根据关联条件将两表关联起来
sql复制代码
select a.first_col, b.second_col
from
(select row_number() over(order by first_col) as id, first_col
from Data) a join
(select row_number() over(order by second_col desc) as id, second_col
from Data) b on a.id = b.id;