FIND_IN_SET有两个字符串

时间:2015-12-30 04:09:06

标签: php mysql laravel-5.1

我有这份员工名单的员工名单

+-----+---------------+-------------+
| ID  |EMPLOYEE_ID    | SKILLS      |
+-----+---------------+-------------+
|  1  |       1       |   3,4       |
+-----+---------------+-------------+
|  2  |       2       |   3,5,2     |
+-----+---------------+-------------+
|  3  |       3       |  1,5        |
+-----+---------------+-------------+

和表POSTED_JOB列出作业

+-----+---------------+-------------+
| ID  |POSTED_JOB_ID  |  JOB_SKILLS |
+-----+---------------+-------------+
|  1  |       1       |   1,2,3     |
+-----+---------------+-------------+
|  2  |       2       |   3,4       |
+-----+---------------+-------------+
|  3  |       3       |   5,4       |
+-----+---------------+-------------+
|  4  |       4       |   5,6       |
+-----+---------------+-------------+

如何通过laravel查询获得与员工技能相对应的技能。

例如,对于employee_id为1的员工,作业将为1,2和3。

我尝试使用find_in_set,但这两个都是列表。     DB :: raw(" find_in_set(EMPLOYEE.SKILLS,POSTED_JOB.JOB_SKILLS)"),DB :: raw(''),DB :: raw('& #39;))

3 个答案:

答案 0 :(得分:1)

$skills = 'select the employee skills';
$skl_arr = explode(',',$skills);
$skl_length = count($skl_arr); 

/ * query * /

$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('')));

}

答案 1 :(得分:0)

您可以尝试加入

DB::table('POSTED_JOB')->leftJoin('EMPLOYEE', function($join){
   $join->on(DB::raw("find_in_set(POSTED_JOB.JOB_SKILLSmEMPLOYEE.SKILLS)"));
});

答案 2 :(得分:0)

您可以尝试在两列中进行搜索。

SELECT * FROM order1 WHERE FIND_IN_SET(order_no,'$foo') OR awb_no IN ('$foo')