本文介绍了FIND_IN_SET有两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个雇员列表的EMPLOYEE表
I have this EMPLOYEE table of employees list
+-----+---------------+-------------+
| ID |EMPLOYEE_ID | SKILLS |
+-----+---------------+-------------+
| 1 | 1 | 3,4 |
+-----+---------------+-------------+
| 2 | 2 | 3,5,2 |
+-----+---------------+-------------+
| 3 | 3 | 1,5 |
+-----+---------------+-------------+
和表POSTED_JOB列出作业
and table POSTED_JOB listing jobs
+-----+---------------+-------------+
| ID |POSTED_JOB_ID | JOB_SKILLS |
+-----+---------------+-------------+
| 1 | 1 | 1,2,3 |
+-----+---------------+-------------+
| 2 | 2 | 3,4 |
+-----+---------------+-------------+
| 3 | 3 | 5,4 |
+-----+---------------+-------------+
| 4 | 4 | 5,6 |
+-----+---------------+-------------+
我如何通过laravel查询发布具有与员工技能相对应的技能的所有职位.
How can I get all jobs posted with skills corresponding to the skills of employees with laravel query.
例如,对于具有employee_id 1的员工,工作将是1,2和3.
For example for employee with employee_id 1, the jobs would be 1,2, and 3.
我尝试过使用find_in_set,但这两个都是列表. DB :: raw("find_in_set(EMPLOYEE.SKILLS,POSTED_JOB.JOB_SKILLS)"),DB :: raw(''),DB :: raw(''))
I tried with find_in_set but here both are lists. DB::raw("find_in_set(EMPLOYEE.SKILLS , POSTED_JOB.JOB_SKILLS)"), DB::raw(''), DB::raw(''))
推荐答案
$skills = 'select the employee skills';
$skl_arr = explode(',',$skills);
$skl_length = count($skl_arr);
/*查询*/
$rows->orwhere(DB::raw("find_in_set('$skl_arr[0]','post_job.skills')"));
for ($i=1; $i < $skl_length ; $i++) {
$rows->$join->on(DB::raw("find_in_set('$skl_arr[$i]','post_job.skills')",DB::raw(''),DB::raw('')));
}
这篇关于FIND_IN_SET有两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!