Oracle SQL 使用连接创建重复行
我想创建重复的行作为输出:首先我想要该行,然后再次将同一行与另一个表连接,如下所示:
table A with fieldA (and lots of others)
table B with fieldB (and lots of others)
输出:
fieldA1 (and all the fileds from tableA)
fieldA1 fieldB1 (and all the fields from tableA and tableB joined)
filedA1 fieldB2
fieldA2
fieldA2 fieldB8
filedA2 fieldB9
. . .
我正在考虑使用联合,但随后我会复制 tableA 的非常复杂的选择以获取 tableA 和 tableB 的行(tableA 是其他表的并集,我只是针对问题简化了它)。有没有“更干净”的解决方案?我知道这是一个不寻常的问题,所以我会感谢任何想法或想法。
预先非常感谢您!
I would like to create duplicated rows as an output: first I would like to have the row, and then the same row again joined with another table, like this:
table A with fieldA (and lots of others)
table B with fieldB (and lots of others)
and the output:
fieldA1 (and all the fileds from tableA)
fieldA1 fieldB1 (and all the fields from tableA and tableB joined)
filedA1 fieldB2
fieldA2
fieldA2 fieldB8
filedA2 fieldB9
. . .
I was thinking about using union, but then I would have to duplicate the very complicated select of tableA to get the rows of tableA and tableB (tableA is union of other tables, I just simplified it for the question). Is there any 'cleaner' solution to this? I know it is an unusual question, so I would appriciate any thougts or ideas.
Thank you very much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改 Benoit 的答案以使用公用表表达式:
Modify Benoit's answer to use a common table expression:
使用:
Use: