2017-02-20 43 views
-2

我有這個表:的毗連查詢的MySQL

reference - model - category 
0001  - NON  - 2 
0001  - NON  - 5 
0001  - NON  - 12 
0001  - SAN  - 2 
0001  - SAN  - 5 
0001  - SAN  - 12 

我要尋找這樣的結果:

reference - model - categories 
0001  - NON  - 2,5,12 
0001  - SAN  - 2,5,12 

我試着用CONCAT及GROUP_CONCAT沒有任何這樣的結果。這在這種情況下可能嗎?

+4

下一次,發佈失敗的努力。 – Strawberry

回答

2
Select reference, model, group_concat(category) categories From tableName 
group by reference, model