【问题标题】:FIND_IN_SET with two strings带有两个字符串的 FIND_IN_SET
【发布时间】:2015-12-30 04:09:06
【问题描述】:

我有这张 EMPLOYEE 员工列表

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

【问题讨论】:

  • 建议标准化您的数据
  • @FirstOne 用户想查看他提到的具有相似技能的工作

标签: php mysql laravel-5.1


【解决方案1】:
$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('')));

}

【讨论】:

    【解决方案2】:

    你可以试试这个加入

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多