sql查询中每行多个结果

时间:2014-10-01 07:10:32

标签: sql postgresql

示例表1

colA
5
3
1

示例表2

colB
2
6
8

我的结果类似于

5    2
5    6
5    8
3    2
etc...

我想要这样的东西

5      2
3      6
1      8

任何有sql经验的人都知道如何摆脱这个?

1 个答案:

答案 0 :(得分:0)

 with cte1 as (
    Select *,row_number () over () as rnk
    from  "#tmp" 
 ), cte2 as (
    Select *,row_number () over () as rnk1 
   from    "#tmp1" 
 )
 Select  colA,colb
 from   cte1 
   inner join cte2 on (rnk = rnk1);