答案 0 :(得分:1)
要以这种方式连接表格,您必须有其他列加入,其中一种可能性是使用ROW_NUMBER()
:
select T1.[date] [Table1_date],
T1.[als] [Table1_als],
T1.[zxc] [Table1_zxc],
T2.[date] [Table2_date],
T2.[bls] [Table2_bls],
T2.[zxc] [Table2_zxc]
from (
select row_number() over (order by [date]) [rn],[date],[als],[zxc] from Table1
) [T1] left /*right - depends which table has more rows*/ join (
select row_number() over (order by [date]) [rn],[date],[bls],[zxc] from Table2
) [T2] on T1.[rn] = T2.[rn]
为了连接多个表(> 2),查询中出现的第一个表应该是具有最大记录数的表。然后,您可以将left join
系列与其余表格一起使用,并加入由row_number()
生成的列。