本文介紹了如何使用 GROUP BY 在 MySQL 中連接字符串?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
基本上問(wèn)題是如何從中獲得:
<前>foo_id foo_name1 安1 乙2 C為此:
<前>foo_id foo_name1 甲乙2 C 解決方案
SELECT id, GROUP_CONCAT(name SEPARATOR ' ') FROM table GROUP BY id;
https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
從上面的鏈接,GROUP_CONCAT
:此函數(shù)返回一個(gè)字符串結(jié)果,其中包含來(lái)自組的連接的非 NULL 值.如果沒(méi)有非 NULL 值,則返回 NULL.
Basically the question is how to get from this:
foo_id foo_name 1 A 1 B 2 C
to this:
foo_id foo_name 1 A B 2 C
解決方案
SELECT id, GROUP_CONCAT(name SEPARATOR ' ') FROM table GROUP BY id;
https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat
From the link above, GROUP_CONCAT
: This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.
這篇關(guān)于如何使用 GROUP BY 在 MySQL 中連接字符串?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!