【问题标题】:Merging values of a column where ID is duplicated [duplicate]合并 ID 重复的列的值 [重复]
【发布时间】:2014-03-12 00:53:49
【问题描述】:

我有一个表,其中的 ID 列可以包含重复项,因为它用作与我的主表匹配的外键。每个 id 可以有多个结果,如下例所示:

ID      FieldValue
1       This
2       Also this
1       and that
3       And additionally, this.
2       and, finally, this.

如何合并 FieldValue 列以使每个 ID 只有一行?例如

ID      FieldValue
1       This;and that
2       Also this;and, finally, this.
3       And additionally, this.

如果必须保留重复的行,我不会担心,例如

ID      FieldValue
1       This;and that
2       Also this;and, finally, this.
1       This;and that
3       And additionally, this.
2       Also this;and, finally, this.

因为我现在可以对它们运行 DISTINCT 查询,因为它们确实是重复的。谷歌搜索了一段时间没有结果;我怀疑是因为它有几个步骤,我需要知道这些步骤是什么,然后搜索才会有成果。

有什么想法吗?

【问题讨论】:

  • 谢谢@GordThompson,已经解决了。我的措辞有误,但会在此处留下这个问题,以防其他人也措辞错误!

标签: sql ms-access concatenation ms-access-2010


【解决方案1】:

如果您使用的是 mysql,您可以尝试以下方法:

SELECT GROUP_CONCAT(FiledValue) As Result FROM tablename WHERE ID= '1'

【讨论】:

  • 嗨 - 谢谢,但它是根据标签的访问权限。
猜你喜欢
  • 2020-05-29
  • 1970-01-01
  • 2023-03-27
  • 2022-07-04
  • 1970-01-01
  • 2018-06-20
  • 2016-08-14
  • 2019-02-14
  • 1970-01-01
相关资源
最近更新 更多