如数据库记录如下:
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 请问上述目的怎么实现?
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 请问上述目的怎么实现?
FROM yourTable
GROUP BY id[align=center]==== 思想重于技巧 ====
[/align]
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]