2013-04-17 49 views
1

我有一個表在我的MySQL像下面PHP 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 
==================================== 

回答

1
SELECT MIN(ID) ID, 
     GROUP_CONCAT(Courses SEPARATOR ', ') Courses, 
     r_Number 
FROM TableName 
GROUP BY r_Number 
ORDER BY ID 

我想知道爲什麼在你的例子中ID與記錄不符,爲什麼?

+1

第二個表是HTML表格。感謝提升。我回到了正軌! – OmniPotens