FIND_IN_SET with two strings

為{幸葍}努か 提交于 2019-12-20 05:45:09

问题


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        |
+-----+---------------+-------------+

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       |
+-----+---------------+-------------+

How can I get all jobs posted with skills corresponding to the skills of employees with laravel query.

For example for employee with employee_id 1, the jobs would be 1,2, and 3.

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


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

}



回答2:


You can try this over join

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



回答3:


You can try this to search in two columns.

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


来源:https://stackoverflow.com/questions/34522759/find-in-set-with-two-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!