문제
group_concat 명령 내에서 concat_ws를 사용하려고합니다. 단순화 된 쿼리를 사용하면 다음과 같습니다.
SELECT item.title, GROUP_CONCAT( CONCAT_WS( ',', attachments.id, attachments.type, attachments.name ) ) as attachments
FROM story AS item
LEFT OUTER JOIN story_attachment AS attachments ON item.id = attachments.item_id
GROUP BY item.id
부착물 열을 블로브 유형으로 얻습니다. Blob 대신 문자열로 얻을 수 있습니까?
해결책
당신은 숯으로 캐스팅해야합니다 ..
SELECT item.title, GROUP_CONCAT( CAST(CONCAT_WS(',', attachments.id,
attachments.type, attachments.name ) as CHAR ) ) as attachments
FROM story AS item
LEFT OUTER JOIN story_attachment AS attachments
ON item.id = attachments.item_id GROUP BY item.id
다른 팁
캐스트가 적절한 답변이라고 생각하지만, 과거에 비슷한 일을하면서 이상/충돌하는 콜레이션 유형과 캐릭터 세트로 밝혀 졌다고 언급 할 가치가 있습니다.
제휴하지 않습니다 StackOverflow