CREATE TABLE `shoufei` ( `id` int(11) NOT NULL AUTO_INCREMENT, `shijian` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `xiangmu` varchar(20) NOT NULL, `jiage` float NOT NULL, `shuliang` int(11) NOT NULL, `jine` float DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
SELECT GROUP_CONCAT(xiangmu) FROM shoufei;
SELECT GROUP_CONCAT(DISTINCT shuliang) FROM shoufei;
SELECT GROUP_CONCAT(xiangmu SEPARATOR '-') FROM shoufei;
SELECT GROUP_CONCAT(xiangmu ORDER BY xiangmu ASC SEPARATOR '-') FROM shoufei;
注意:html
group_concat字符串的長度字節超過1024 則會被截斷,能夠經過命令 "show variables like 'group_concat_max_len' " 來查看group_concat 默認的長度。mysql
設置group_concat長度的操做方法:sql
(1)在MySQL配置文件中加入:數據庫
group_concat_max_len = 102400spa
(2)更簡單的操做方法,執行SQL語句:code
SET GLOBAL group_concat_max_len = 102400;htm
SET SESSION group_concat_max_len = 102400;blog
注意:該方法缺點是重啓服務後設置失效。排序
本文轉自:https://jingyan.baidu.com/album/29697b91478e91ab20de3c9d.html?picindex=1ci