select *,(SELECT STUFF((SELECT ',' + NAME FROM Emp where CHARINDEX(ID,EMP_ID)>0 for xml path('')),1,1,'')) as EMP_NAME from DeptDept
SQLSERVER的语法.
dept:
emp:
SQL:
select dept.*,group_concat(emp.NAME
separator '/')
from dept,emp
where instr(concat('/',dept.EMP_ID,'/'),concat('/',emp.ID,'/'))
group by dept.ID,dept.NAME
,dept.EMP_ID
结果: