sql合并同一字段下的其他字段

sqlServer

SELECT subject_type,
 stuff((select ','+subject_title from  sjycxy_subject  
 where c.subject_type=subject_type for xml path('')),1,1,'') as subject_title  
 from sjycxy_subject s   group by s.subject_type 
 <!--sqlServer -->

mysql

SELECT subject_type,single_or_many,subject_username,
GROUP_CONCAT(subject_title SEPARATOR ';'),
FROM sjycxy_subject GROUP BY subject_type;

sjycxy_subject 表名
subject_type 条件字段
subject_title 需要合并的字段

注意:两个语句有差别,分别是不同的数据库

上一篇:几何(Geometry)


下一篇:java Mycat Shiro权限框架