SQL: MySQL: Function: column switch (Switch to a field): the value GROUP_CONCAT, the packet will be merged into a column line

CREATE TABLE `testmysql_group_concat` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `userid` varchar(50) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=650 DEFAULT CHARSET=utf8mb4 COMMENT='测试表'

select userid,GROUP_CONCAT(name SEPARATOR ',') from testmysql_group_concat group by userid

Published 260 original articles · won praise 119 · views 510 000 +

Guess you like

Origin blog.csdn.net/weixin_38750084/article/details/104023451