我有mysql表这个结构:
id || groupid || name
1 || 23 || John
2 || 25 || Maria
3 || 23 || William
现在我如何按组 id 对它进行分组以获得这个结果:
23 - John,William
25 - Maria
SELECT groupid, GROUP_CONCAT(name separator ',') as groupname FROM table GROUP BY groupid;
SQLFIDDLE 解决方案:
SQLFIDDLE:http ://sqlfiddle.com/#!2/db32d/15