【问题标题】:Join values in different rows into one cloumn将不同行中的值合并为一列
【发布时间】:2013-07-18 02:09:32
【问题描述】:

我有一个包含事件列表的表格。我想根据唯一值“事件”将多行中的单位值合并到一列中以进行显示。

当前数据:

Date Time Incident Unit
1/1  1200  1234    101
1/1  1200  1234    102

我想如何显示它:

Date Time Incident Unit
1/1  1200  1234    101, 102

我正在使用 mysql/php。

谢谢!

【问题讨论】:

标签: php mysql sql


【解决方案1】:

试试这个查询:

SELECT `date`, `time`, `incident`, group_concat(`unit`) 
from table group by `incident`

【讨论】:

    【解决方案2】:

    使用这个查询

    SELECT date, time, incident, GROUP_CONCAT(unit SEPARATOR ", ") AS unit FROM table GROUP_BY incident
    

    【讨论】:

      猜你喜欢
      • 2019-05-24
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 2022-09-23
      • 2021-12-28
      • 1970-01-01
      相关资源
      最近更新 更多