如何水平显示1列的值-SQL?
我对SQL有很小的知识,但是我正在尝试根据Confluence Macro的过滤器创建一个SQL表。
我有2个表,我不确定如何编写SQL来显示我的需求。
表名= T1
| Key | Title | Developer | Links |
| ---- | ----- | --------- | ------------------- |
| RD-1 | Gray | Jon Cruz | PD-2, LD-4 |
| RD-2 | Blue | Drew Lee | PD-30, LD-12, PD-23 |
表名称= T2
| Key | Assignee | Links |
| ----- | ---------- | ----------- |
| PD-30 | Kurt Penn | RD-2 |
| PD-2 | Jury Souk | RD-1, LD-4 |
| LD-4 | Grace Chen | RD-1, PD-2 |
| LD-12 | Gram Bron | RD-2, PD-23 |
| PD-23 | Peter Tiu | RD-2, LD-12 |
结果表应该是:
| Key | Title | Developer | PD Assignee | LD Assignee |
| ---- | ----- | --------- | -------------------- | ----------- |
| RD-1 | Gray | Jon Cruz | Jury Souk | Grace Chen |
| RD-2 | Blue | Drew Lee | Kurt Penn, Peter Tiu | Gram Bron |
使用我尝试的内容,它显示了RD-1和RD-2的多行。
然后,我要做的是为PD和LD提供单独的表格,并使用了多个左连接(如下),但想限制表的数量,因此我想请求您的帮助。
SELECT
T1.Key, T1.Title, T1.Developer, T2.'Assignee' PD Assignee,
T3.'Assignee' 'PD2 Assignee', T4.'Assignee' 'LD Assignee',
FROM
T1 LEFT JOIN T2 ON T1.'Key' IN T2.'Links'
LEFT JOIN T3 ON T1.'Key' IN T3.'Links'
LEFT JOIN T4 ON T1.'Key' IN T4.'Links';
谢谢你!
I have a very small knowledge of sql, but I'm trying to create an sql table based on filter from Confluence macro.
I have 2 tables and I'm not sure how to write the sql to show what I need.
Table name = T1
| Key | Title | Developer | Links |
| ---- | ----- | --------- | ------------------- |
| RD-1 | Gray | Jon Cruz | PD-2, LD-4 |
| RD-2 | Blue | Drew Lee | PD-30, LD-12, PD-23 |
Table name = T2
| Key | Assignee | Links |
| ----- | ---------- | ----------- |
| PD-30 | Kurt Penn | RD-2 |
| PD-2 | Jury Souk | RD-1, LD-4 |
| LD-4 | Grace Chen | RD-1, PD-2 |
| LD-12 | Gram Bron | RD-2, PD-23 |
| PD-23 | Peter Tiu | RD-2, LD-12 |
Resulting Table should be:
| Key | Title | Developer | PD Assignee | LD Assignee |
| ---- | ----- | --------- | -------------------- | ----------- |
| RD-1 | Gray | Jon Cruz | Jury Souk | Grace Chen |
| RD-2 | Blue | Drew Lee | Kurt Penn, Peter Tiu | Gram Bron |
With what I tried, it's showing multiple rows of RD-1 and RD-2.
What I did then is to have separate tables for PD and LD and used multiple left joins (like below), but would like to limit the number of tables, so I would like to request your help please.
SELECT
T1.Key, T1.Title, T1.Developer, T2.'Assignee' PD Assignee,
T3.'Assignee' 'PD2 Assignee', T4.'Assignee' 'LD Assignee',
FROM
T1 LEFT JOIN T2 ON T1.'Key' IN T2.'Links'
LEFT JOIN T3 ON T1.'Key' IN T3.'Links'
LEFT JOIN T4 ON T1.'Key' IN T4.'Links';
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不喜欢加入,则可以尝试这样的尝试)。因此,如果是这样,您可以将其标记为答案。
If you don't like joins you can try someting like this ). So, you can mark this as answer if it's it.