【问题标题】:Join unrelated table with unequal rows用不相等的行连接不相关的表
【发布时间】:2021-06-02 15:04:46
【问题描述】:

我想将表 A、表 B 和表 C 连接为附件中的预期结果。

【问题讨论】:

  • 您不是在寻找CROSS JOIN。所以你想要完成的事情还不清楚。

标签: sql salesforce salesforce-marketing-cloud


【解决方案1】:

您可以枚举行并将其用于加入。 . .这可能是你想要的:

select ab.*, c.*
from (select a.*, b.*,   -- really list out the columns you want
             row_number() over (order by accountid) as seqnum
      from a join
           b
           on a.accountid = b.accountid
     ) ab join
     (select c.*, row_number() over (order by code) as seqnum
      from c
     ) c
     on ab.seqnum = c.seqnum

【讨论】:

  • 嗨,Gordon Linoff,非常感谢,这对您有很大帮助!将 JOIN 添加到您的示例代码中将完美运行。 select ab.*, c.* from (select a.*, b.*, -- 真正列出你想要 row_number() 覆盖的列(按 accountid 排序)作为 a.accountid = b 上的连接 b 中的 seqnum。 accountid ) ab JOIN (select c.*, row_number() over (order by code) as seqnum from c ) c on ab.seqnum = c.seqnum
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
相关资源
最近更新 更多