【问题标题】:SQL join or concatenate multiple record text fields with same foreign keySQL连接或连接具有相同外键的多个记录文本字段
【发布时间】:2015-11-15 21:47:58
【问题描述】:

这可能是一个简单的问题,由于某种原因我看不到答案。这是示例数据:

+----+----------+---------------------------+
| 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.   |
+----+----------+---------------------------+

请原谅菜鸟桌。这有多可怕?!

我想要的是一些 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.            |
+----------+---------------------------------------------------+

提前致谢!

【问题讨论】:

标签: sql database oracle foreign-keys concatenation


【解决方案1】:

所以在听取了 Gordon 的建议并访问了another page 之后,我为 oracle 找到了这个答案:

选择 F_Key_ID,
替换(wm_concat(Desc_Text), ',' , ' ') AS Concat_Text
FROM 数据库名称
按 F_Key_ID 分组;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2020-11-26
  • 1970-01-01
  • 2014-03-11
  • 2013-10-26
  • 1970-01-01
相关资源
最近更新 更多