如数据库记录如下: 
id  val  date 
1    a   2008-1-1 
1    b   2008-1-2 
2    c   2008-1-3 
2    d   2008-1-4 
1    e   2008-1-5 通过id字段汇总时,把val字段拼接起来 
结果是: 
id   val 
1    a,b,e 
2    c,d 请问上述目的怎么实现?

解决方案 »

  1.   

    select id,group_concat(VAL) as VAL from TT group by ID
      

  2.   

    SELECT id,GROUP_CONCAT(val) as val 
    FROM yourTable 
    GROUP BY id[align=center]====  ====
    [/align]
      

  3.   

    以下摘自 MySQL 5.1 Reference ManualGROUP_CONCAT(expr) 

    This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values. The full syntax is as follows: GROUP_CONCAT([DISTINCT] expr [,expr ...]
                 [ORDER BY {unsigned_integer | col_name | expr}
                     [ASC | DESC] [,col_name ...]]
                 [SEPARATOR str_val])
    Or: 
    [align=center]====  ====
    [/align]