sql合併同一欄位下的其他欄位
阿新 • • 發佈:2020-12-05
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 需要合併的欄位
注意:兩個語句有差別,分別是不同的資料庫