selecttype,user_name= (stuff((select ',' + name from tableName where type= a.type for xml path('')),1,1,''))
from tableName a group by type
--user_name 别名
--name 数据库需要整合到一个字段的信息
--tableName 表名称
--type 分组字段
selecttype,user_name= (stuff((select ',' + name from tableName where type= a.type for xml path('')),1,1,''))
from tableName a group by type
--user_name 别名
--name 数据库需要整合到一个字段的信息
--tableName 表名称
--type 分组字段
转载于:https://www.cnblogs.com/xy0710/p/11053288.html