任务表
id assign_to task
1 1,2,4 Development
2 2,5,3 Testing
员工表
id Name
1 Dhawan
2 Sachin
3 Dhoni
4 Virat
5 Rohit
在这里,我试图从employee表中获取所有雇员的姓名,并在任务表中获取assign_to字段。因此我的输出将在以下
id assign_to task
1 Dhawan, Sachin,Virat Development
2 Virat, Rohit, Dhoni Testing
在我写的查询下面。谁能建议我对此进行查询
select t.*, from task t inner join employee e on e.id in (t.assign_to)
答案 0 :(得分:1)
将查询更新为:
select t.*, from task t inner join
employee e on FIND_IN_SET(e.id, t.assign_to) > 0
GROUP BY e.id
答案 1 :(得分:0)
请尝试这个
select task.id,
(select group_concat(employee.name,',')
from employee employee
where find_in_set(employee.id, task.assign_to)> 0 ) as emp ,
task.task
from task task;