2016-11-23 61 views
-1

我有以下數據的數據庫表:MySQL的選擇不同沒有得到所需的查詢結果

+--------------------+-----------------------------+ 
| order_no  | part      | 
+--------------------+-----------------------------+ 
| AAAAAAAAAAAAA  | QQQQQQQQ-WWW    | 
| AAAAAAAAAAAAA  | EEEEEEEE-TTT    | 
| BBBBBBBBBBBBB  | 33333333-333    | 
| BBBBBBBBBBBBB  | 44444444-444    | 
| BBBBBBBBBBBBB  | EEEEEEEE-TTT    | 
+--------------------+-----------------------------+ 

我的問題是,我無法作出查詢,以產生這樣的結果:

+----------------+-------------------------------------------+ 
| order_no | part         | 
+----------------+-------------------------------------------+ 
| AAAAAAAAAAAAA | QQQQQQQQ-WWW, EEEEEEEE-TTT    | 
| BBBBBBBBBBBBB | 33333333-333, 44444444-444, EEEEEEEE-TTT | 
+----------------+-------------------------------------------+ 

提前致謝。

+0

您正在尋找http://dev.mysql.com/doc/refman/5.7 /en/group-by-functions.html#function_group-concat – phobia82

回答

0

group_concat聚合函數正是醫生下令:

SELECT order_no, GROUP_CONCAT(part SEPARATOR ', ') 
FROM  mytable 
GROUP BY order_no 
+0

謝謝Mureinik – DigitalMandrake

-1

試試這個:

SELECT order_no, GROUP_CONCAT(string SEPARATOR ', ') FROM table GROUP BY order_no; 
+0

感謝JoaquinSiabra – DigitalMandrake