将两个mysql行合并为一个

时间:2013-11-22 21:29:39

标签: mysql

我在mysql数据库表中有以下两行

  Chart_date      chart_field            chart_counts
  20131115  user_jrFeed_item_count      {"1":2}
  20131115  user_jrForum_item_count     {"1":1}

如何创建另一行以实现以下结果

Chart_date    chart_field                                 chart_counts
  20131115  user_jrFeed_item_count,user_jrForum_item_count  {"1":2},{"1":1}

OR

  Chart_date    chart_field   chart_counts
  20131115  new description   {"1":2},{"1":1}

1 个答案:

答案 0 :(得分:2)

SELECT Chart_date,GROUP_CONCAT(chart_field )as chart_field,
REPLACE(GROUP_CONCAT(chart_counts),'2},{','2,')as chart_counts 
FROM table WHERE Chart_date='20131115' GROUP BY Chart_date