如何在SQL中混合两种结果(包括示例)
我正试图找到一种方法,以这种方式混合数据: 表A:如何在SQL中混合两种结果(包括示例),sql,Sql,我正试图找到一种方法,以这种方式混合数据: 表A: 1 2 3 4 5 表B: a b c d e 混合成: 1 a 2 b 3 c 4 d 5 e 这是一个排序问题: select col from ((select col, 1 as which, row_number() over (order by col) as seqnum from a ) union all (select col, 2 as which, row_number() o
1
2
3
4
5
表B:
a
b
c
d
e
混合成:
1
a
2
b
3
c
4
d
5
e
这是一个排序问题:
select col
from ((select col, 1 as which, row_number() over (order by col) as seqnum
from a
) union all
(select col, 2 as which, row_number() over (order by col) as seqnum
from b
)
) ab
order by seqnum, which
这是一个排序问题:
select col
from ((select col, 1 as which, row_number() over (order by col) as seqnum
from a
) union all
(select col, 2 as which, row_number() over (order by col) as seqnum
from b
)
) ab
order by seqnum, which
使用
UNION ALL
和行号()
使用UNION ALL
和行号()
假设A和B中的列具有相同的数据类型。@PM77-1。这是OPs结果的必要假设。此注释应针对问题。假设A和B中的列具有相同的数据类型。@PM77-1。这是OPs结果的必要假设。这个评论应该是关于这个问题的。