SQL 使用相同的外键加入或连接多个记录文本字段
SQL join or concatenate multiple record text fields with same foreign key
这可能是一个简单的问题,但由于某种原因我看不到答案。这是示例数据:
+----+----------+---------------------------+
| ID | F_Key_ID | Desc_Text |
+----+----------+---------------------------+
| 1 | 15 | This is an example |
| 2 | 15 | that I wished worked |
| 3 | 15 | correctly |
| 4 | 21 | Unique entry |
| 5 | 18 | The Eagles are |
| 6 | 18 | the best football team. |
+----+----------+---------------------------+
菜鸟见谅table。这有多糟糕?!
我想要的是一些 SQL,它采用每个 F_Key_ID 共有的文本并将其连接在一起,如下所示:
+----------+---------------------------------------------------+
| F_Key_ID | Concat_Text |
+----------+---------------------------------------------------+
| 15 | This is an example that I wished worked correctly |
| 21 | Unique entry |
| 18 | The Eagles are the best football team. |
+----------+---------------------------------------------------+
提前致谢!
所以在听取了 Gordon 的建议并访问了 another page 之后,我找到了 oracle 的这个答案:
SELECT F_Key_ID,
替换(wm_concat(Desc_Text), ',' , ' ') AS Concat_Text
FROM 数据库名称
分组 F_Key_ID;
这可能是一个简单的问题,但由于某种原因我看不到答案。这是示例数据:
+----+----------+---------------------------+
| ID | F_Key_ID | Desc_Text |
+----+----------+---------------------------+
| 1 | 15 | This is an example |
| 2 | 15 | that I wished worked |
| 3 | 15 | correctly |
| 4 | 21 | Unique entry |
| 5 | 18 | The Eagles are |
| 6 | 18 | the best football team. |
+----+----------+---------------------------+
菜鸟见谅table。这有多糟糕?!
我想要的是一些 SQL,它采用每个 F_Key_ID 共有的文本并将其连接在一起,如下所示:
+----------+---------------------------------------------------+
| F_Key_ID | Concat_Text |
+----------+---------------------------------------------------+
| 15 | This is an example that I wished worked correctly |
| 21 | Unique entry |
| 18 | The Eagles are the best football team. |
+----------+---------------------------------------------------+
提前致谢!
所以在听取了 Gordon 的建议并访问了 another page 之后,我找到了 oracle 的这个答案:
SELECT F_Key_ID,
替换(wm_concat(Desc_Text), ',' , ' ') AS Concat_Text
FROM 数据库名称
分组 F_Key_ID;