mysql分组并多行拼接--group_concat和group by的使用

mysql分组并多行拼接--group_concat和group by的使用创建表结构 DROP TABLE IF EXISTS exe CREATE TABLE exe id int 3 NOT NULL type int 3 default NULL name varchar 10 default NULL other int 3 default NULL text int 255 default NULL

大家好,我是讯享网,很高兴认识大家。

– 创建表结构


DROP TABLE IF EXISTS exe;
CREATE TABLE exe (
id int(3) NOT NULL,
type int(3) default NULL,
name varchar(10) default NULL,
other int(3) default NULL,
text int(255) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


– 插入测试数据


INSERT INTO exe VALUES (‘1’, ‘1’, ‘分拼’, ‘2’, ‘1’);
INSERT INTO exe VALUES (‘2’, ‘1’, ‘四维’, ‘3’, ‘2’);
INSERT INTO exe VALUES (‘3’, ‘2’, ‘总评’, ‘1’, ‘4’);
INSERT INTO exe VALUES (‘4’, ‘3’, ‘季度’, ‘5’, ‘3’);


– group_concat和group by的使用



讯享网

select t.type,group_concat(t.name order by t.other) “result” from exe t group by t.type;

select t.type,group_concat(t.name) “name”,group_concat(CAST(t.other AS char)) “result” from exe t group by t.type;

http://blog.csdn.net/priestmoon/article/details/

http://www.jb51.net/article/40179.htm

小讯
上一篇 2025-03-13 22:17
下一篇 2025-03-19 09:43

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/71841.html