sql 分组后把字段拼起来
作者:互联网
按老师的ID分类后,将对应的班级ID用 “/” 拼接起来
Sqlserver
SELECT 字段1,
[随便来个名字就行] = stuff((
SELECT '/' + [年级2] FROM aa t
WHERE t.老师ID = aa.老师ID FOR xml path('')) , 1 , 1 , '')
FROM aa
GROUP BY 老师ID
Mysql、Oracle
SELECT
老师ID,
group_concat(年级ID separator '/')class,
FROM table_name
GROUP BY 老师ID
标签:aa,起来,GROUP,老师,分组,sql,年级,ID,SELECT 来源: https://blog.csdn.net/super_qing_/article/details/120370639