按老师的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