GROUP_CONCAT(DISTINCT
时间: 2023-11-08 11:42:01 浏览: 104
GROUP_CONCAT的用法
5星 · 资源好评率100%
GROUP_CONCAT(DISTINCT) is a MySQL function that concatenates values from multiple rows into a single string. The DISTINCT keyword ensures that each value is only included once in the concatenated string.
For example, if we have a table "students" with columns "id" and "subject", and we want to concatenate all distinct subjects for a particular student, we could use the following query:
SELECT GROUP_CONCAT(DISTINCT subject) FROM students WHERE id = 1;
This would return a string of all the distinct subjects for student with id = 1.
阅读全文