2015-12-30 124 views
0

我的員工名單這個EMPLOYEE表FIND_IN_SET兩個字符串

+-----+---------------+-------------+ 
| 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 ::原始( 「FIND_IN_SET(EMPLOYEE.SKILLS,POSTED_JOB.JOB_SKILLS)」),DB ::原始( ''),DB ::原始( ''))

+0

建議您規範化數據 – amdixon

+0

@FirstOne用戶想看到他所提出類似的技能作業 – tyro

回答

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

} 
0

你可以試試這個在加入

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