合并两个没有关系的表

Merging two tables with no relationship

我需要合并两个来源,一个是一个分段 table,其中包含具有多个属性的三行数据,它包含 table_ididentification、[=12= 等数据] 和更多。另一个 table 有三行,包含一个 table_id 和一个数字。

我想将这两个 table 合并在一起只输出三行,所以我想按原样合并。我的意思是,来自暂存 table 的第一行将 "add" 作为该行的另一个属性的数字。

table没有key关系,所以没办法link起来。我所做的是在 id 上使用左外连接的合并连接,它起作用了,但这是错误的方法,我认为这只是因为 table_id 是相同的。

这是我所做的:

有什么办法可以解决这个问题?我在 SSIS 中所做的是从源文件中提取,我用这些数据填充我的星型模式维度,还有一个暂存 table。然后我分析来自源文件的聊天评论的情绪并将其存储在维度 table 中,最终将所有信息插入事实 table.

使用ROW_NUMBER() window函数连接表格:

select t1.table_id, t1.identification, t1.date, t2.numbercolumn
from (
  select *, row_number() over (order by table_id) rn
  from table1
) t1 left join (
  select *, row_number() over (order by table_id) rn
  from table2
) t2 on t2.rn = t1.rn

两个表按 id 排序,因此两个表中的列 rn 的值为 1,2,3...