我有一个包含以下数据的数据库表:
+--------------------+-----------------------------+
| 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 :(得分:0)
group_concat
聚合功能正是医生所要求的:
SELECT order_no, GROUP_CONCAT(part SEPARATOR ', ')
FROM mytable
GROUP BY order_no
答案 1 :(得分:-1)
试试这个:
SELECT order_no, GROUP_CONCAT(string SEPARATOR ', ') FROM table GROUP BY order_no;