当运行以下查询时
SELECT job_id ,GROUP_CONCAT(roles_title) from jobs left join roles on roles_id in (roles) group by job_id
预期结果
<table>
<tr>
<td>Job_id</td>
<td>Roles</td>
</tr>
<tr>
<td>1</td>
<td>Admin,acc & test</td>
</tr>
<tr>
<td>2</td>
<td>acc& test</td>
</tr>
</table>
最佳答案
您可以在 join 子句中使用 FIND_IN_SET()
。
SELECT job_id ,GROUP_CONCAT(roles_title SEPARATOR '&')
from jobs
left join roles on FIND_IN_SET(roles_id,roles)
GROUP BY job_id
希望这有帮助。
关于mysql - 组 concat 和 in 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33826832/