如何将两个或多个 table 合并为一个 table 并包含所有 table 的所有列名称

How can I merge two or more table into a single table with all columns name of all tables

如何将两个或多个 table 合并为一个 table 并包含所有 table 的所有列名称 This is table1

This is table2

Can I get new table like this

要以这种方式加入 table,您必须有额外的列才能加入,其中一种可能性是使用 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]

为了连接多个 tables (>2),查询中出现的第一个 table 应该是具有最大记录量的一个。然后,您可以将 left join 系列与 table 的其余部分一起使用,加入由 row_number().

生成的列