這裏是一個示例即會爲你工作
和一個新的使用DISTINCT
SELECT
school,
`name`,
GROUP_CONCAT(`point` SEPARATOR ' and ')
FROM (SELECT DISTINCT school,`name`, `point` FROM groupme) AS result
GROUP BY school,`NAME`;
SELECT
school,
`name`,
GROUP_CONCAT(`point` SEPARATOR ' and ')
FROM groupme
GROUP BY school,`name`;
樣品
MariaDB [mysql]> select * from groupme;
+----+--------+------+---------+
| id | school | name | point |
+----+--------+------+---------+
| 1 | first | dani | good |
| 2 | first | dani | precise |
| 3 | third | John | nice |
| 4 | first | dani | pro |
| 5 | third | John | cute |
+----+--------+------+---------+
5 rows in set (0.01 sec)
MariaDB [mysql]> SELECT school, `name` , GROUP_CONCAT(`point` SEPARATOR ' and ')
-> FROM groupme
-> GROUP BY school,`name`;
+--------+------+------------------------------------------+
| school | name | GROUP_CONCAT(`point` SEPARATOR ' and ') |
+--------+------+------------------------------------------+
| first | dani | good and precise and pro |
| third | John | nice and cute |
+--------+------+------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [mysql]>
見GROUP_CONCAT – Strawberry
做你想要一個實際的新表,其中的數據是格式化的,或者你只是需要它在你的PHP代碼中使用某種數組? – Pevara
我想刪除重複項,並保持一行此更新 – Ricardo