我有一个表在我的MySQL像下面
============================
id | courses | r_number
----------------------------
1 | English | C/009
2 | Maths | C/009
3 | English | C/003
4 | Maths | C/002
============================
我如何输出它像下面的HTML表
====================================
id | courses | r_number
------------------------------------
1 | English, Maths | C/009
2 | English | C/003
3 | Maths | C/002
====================================
SELECT MIN(ID) ID,
GROUP_CONCAT(Courses SEPARATOR ', ') Courses,
r_Number
FROM TableName
GROUP BY r_Number
ORDER BY ID
- <
- SQLFiddle演示/gh>
我想知道为什么在你的例子中ID
与记录不匹配,为什么?