Mysql ',' 난 할 수 있는 사용하여 다음과 같은 항목을
SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
shopping
fishing
coding
대신 난 그냥 1 행, 1 열:
shopping, fishing, coding
['GROUP_CONCAT'] [그룹 concat] 사용할 수 있습니다.
SELECT person_id, GROUP_CONCAT(hobbies SEPARATOR ', ')
FROM peoples_hobbies
GROUP BY person_id;
루트비히 명시된 대로 [그의 발언은,] [루트비히] '다른' 연산자입니다 중복을 피하기 위해 추가할 수 있습니다.
SELECT person_id, GROUP_CONCAT(DISTINCT hobbies SEPARATOR ', ')
FROM peoples_hobbies
GROUP BY person_id;
얀 [그들의 의견] [얀] 로 명시된 값을 사용하여 '이' ORDER BY 내파 전에 정렬하려면 수도 있습니다.
SELECT person_id, GROUP_CONCAT(hobbies ORDER BY hobbies ASC SEPARATOR ', ')
FROM peoples_hobbies
GROUP BY person_id;
[그의 발언은,] [다그] 로 명시된 dag () 는 1024년 바이트입니다 제한값 그 결과에 대한. 이를 해결하기 위해서는, 먼저 쿼리하지 실행하십시오 질의와:
SET group_concat_max_len = 2048;
물론 필요에 따라 '2048년' 변경할 수 있습니다. 계산하고 할당하십시오 가치:
SET group_concat_max_len = CAST(
(SELECT SUM(LENGTH(hobbies)) + COUNT(*) * LENGTH(', ')
FROM peoples_hobbies
GROUP BY person_id)
AS UNSIGNED
);
[그룹 concat]: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html # function_group-concat [다그]: # comment12638055_276949 https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field/276949 [루트비히]: https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field # comment14513101_276949 [1월]: https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field # comment72475644_276949
Mysql 은 버전 (4.1) '' GROUP_CONCAT 경우 투명지에 look at it. [문서] [1] 에서 자세한 내용을 참조.
다음과 같은 항목을 볼 수 있지 않을까 생각한다 "고 말했다
SELECT GROUP_CONCAT(hobbies SEPARATOR ', ')
FROM peoples_hobbies
WHERE person_id = 5
GROUP BY 'all';
[1]: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html # function_group-concat
대체 구문을 연결, 여러 개별 행뿐만 #
내가 내 자신을 com/downloads/global/corporate/iar/esg_prosupport. 이므로, 여러 개별 rows-instea * 일부 그룹 및 의 연결 따랐던 현장.
+------------+--------------------+-------+
| product_id | name | price |
+------------+--------------------+-------+
| 13 | Double Double | 5 |
| 14 | Neapolitan Shake | 2 |
| 15 | Animal Style Fries | 3 |
| 16 | Root Beer | 2 |
| 17 | Lame T-Shirt | 15 |
+------------+--------------------+-------+
그럼 당신은 선사하고 있는 일부 슈만시 돌림무늬 ajax 로 오프하도록 확인란 정리되어 있습니다.
네 배고픈 히포 (hippo) 사용자가 '13, 15, 16'. 오늘 애디슨에게 위한 디저트 없습니다.
'GROUP_CONCAT 사용하여' 를 [이 '의' 조항을] (http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html # function_in):
mysql> SELECT GROUP_CONCAT(name SEPARATOR ' + ') AS order_summary FROM product WHERE product_id IN (13, 15, 16);
어떤 출력입니다:
+------------------------------------------------+
| order_summary |
+------------------------------------------------+
| Double Double + Animal Style Fries + Root Beer |
+------------------------------------------------+
스케쳐내 [' (SUM)'] 에서 총 가격 역시 토스 (http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html # function_sum):
mysql> SELECT GROUP_CONCAT(name SEPARATOR ' + ') AS order_summary, SUM(price) AS total FROM product WHERE product_id IN (13, 15, 16);
+------------------------------------------------+-------+
| order_summary | total |
+------------------------------------------------+-------+
| Double Double + Animal Style Fries + Root Beer | 10 |
+------------------------------------------------+-------+
PS: # 39 사과를 don& 없는 경우, [ui_policytable_java_spe_policy 인앤아웃] (http://www.in-n-out.com) 있다.
최대 길이는 GROUP_CONCAT 설정하여 값을 변경할 수 있습니다 '' 'group_concat_max_len' 매개변수입니다.
자세한 사항은 의 [MySQL 도쿠만테이션] [1].
[1]: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html # function_group-concat
난 이미 제가 더 복잡한 쿼리하지 '외부' 에서 발견되는 사용해야 했습니다 GROUP_CONCAT 쿼리하지 afaq 사용할 수 있습니다.
SELECT DISTINCT userID
FROM event GROUP BY userID
HAVING count(distinct(cohort))=2);
SELECT GROUP_CONCAT(sub.userID SEPARATOR ', ')
FROM (SELECT DISTINCT userID FROM event
GROUP BY userID HAVING count(distinct(cohort))=2) as sub;
누군가 이 도움이 될 수 있다.