作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
目前我正在搭建一个招聘平台。雇主可以发布工作并接收申请。雇主可以设置求职者必须匹配的许多技能要求。求职者还可以添加他们拥有的许多技能。
我想知道的是每个 jobseekers_skills
有多少匹配 employer_requirements
对于每个作业,以便在 View 中显示百分比匹配。理想情况下,我想根据 skill_string
找到匹配项存在于 jobseeker_skills
中表和employer_requirements
table
以下是 3 个表中每一个的数据库安排:
应用:id | job_string | jobseeker_string | employer_string | application_string | date_created
雇主要求:id | skill_name | requirement_level | skill_string | job_string | employer_string | date_created
求职者_技能:id | skill_name | level | jobseeker_string | skill_string | string | date_created
我有以下代码可以获取所有 applications
基于传递的'$job_str'。下面的代码只是一个简单的获取,但不确定从哪里开始。
function skills_match($job_str){
$this->db->select('*')
->from('applications')
->where('job_string', $job_str)
->join('users', 'users.string = applications.jobseeker_string', 'left');
$applications = $this->db->get();
return $applications;
}
+--------+------------------+------------------+------------------+
| id | job_string | jobseeker_string | employer_string |
+--------+------------------+------------------+------------------+
| 1 | vs71FVTBb12DdGlf | uMIsuDJaBuDmo8iq | biQxyPekn6iayIgm |
| 2 | vs71FVTBb12DdGlf | x7phHsVnwJ1K1yHy | biQxyPekn6iayIgm |
| 3 | vs71FVTBb12DdGlf | Fm1TIJLxz6Xg6QPk | biQxyPekn6iayIgm |
+--------+------------------+------+-----+---------+-------+------+
+--------+------------------+-------------+------------------+------------------+
| id | job_string | skill_name | skill_string | employer_string |
+--------+------------------+-------------+------------------+-----------------+|
| 1 | vs71FVTBb12DdGlf |PHP | 9Y8XeCWqJXzkZ5dD | biQxyPekn6iayIgm |
| 2 | vs71FVTBb12DdGlf |JavaScript | O6es19t5CgcRHvct | biQxyPekn6iayIgm |
| 3 | vs71FVTBb12DdGlf |HTML | wx4evsXC62BWiN7p | biQxyPekn6iayIgm |
| 4 | vs71FVTBb12DdGlf |Python | jx15rH1vrGLmsVmq | biQxyPekn6iayIgm |
| 5 | vs71FVTBb12DdGlf |SQL | EksP7mEip0Hs4zKd | biQxyPekn6iayIgm |
| 6 | vs71FVTBb12DdGlf |LESS | fj40m4hkiuDGtbzr | biQxyPekn6iayIgm |
+--------+------------------+-------------+------+-----+---------+-------+------+
求职者技能 - 示例数据:
+--------+------------------+------------------+------------------+
| id | jobseeker_string | skill_name | skill_string |
+--------+------------------+------------------+------------------+
| 1 | uMIsuDJaBuDmo8iq | PHP | 9Y8XeCWqJXzkZ5dD |
| 2 | uMIsuDJaBuDmo8iq | Backbone | 4VIiAxZoL1VbPnTa |
| 3 | x7phHsVnwJ1K1yHy | LESS | fj40m4hkiuDGtbzr |
| 2 | x7phHsVnwJ1K1yHy | Ruby | gTZg4fwYuzMMFcBw |
| 3 | x7phHsVnwJ1K1yHy | SQL | EksP7mEip0Hs4zKd |
| 1 | Fm1TIJLxz6Xg6QPk | PHP | 9Y8XeCWqJXzkZ5dD |
| 2 | Fm1TIJLxz6Xg6QPk | Python | jx15rH1vrGLmsVmq |
| 3 | Fm1TIJLxz6Xg6QPk | HTML | wx4evsXC62BWiN7p |
| 3 | Fm1TIJLxz6Xg6QPk | Git | aR9B9ns1sHlGrzFw |
+--------+------------------+------+-----+---------+-------+------+
uMIsuDJaBuDmo8iq - 1/6 (16.666%)
x7phHsVnwJ1K1yHy - 2/6 (33.333%)
Fm1TIJLxz6Xg6QPk - 3/6 (50%)
最佳答案
首先,这是2个问题:
select *
from Requirements r
inner join Jobseeker j
on r.skill_string = j.r.skill_string
where job_string = 'vs71FVTBb12DdGlf';
select
jobseeker_string,
count(1) / (select count(1) from Requirements where job_string = 'vs71FVTBb12DdGlf') as match_percentage
from Requirements r
inner join Jobseeker j
on r.skill_string = j.r.skill_string
where job_string = 'vs71FVTBb12DdGlf'
group by jobseeker_string;
select
job_string,
count(1) / (select count(1) from Requirements where jobseeker_string = 'uMIsuDJaBuDmo8iq') as my_match,
count(1) / (select count(1) from Requirements where job_string = r.job_string) as job_match
from Requirements r
inner join Jobseeker j
on r.skill_string = j.r.skill_string
where jobseeker_string = 'uMIsuDJaBuDmo8iq'
group by job_string;
select * from
([[insert the above query here]]) t
order by field.
select
job_string,
jobseeker_string
count(1) / (select count(1) from Requirements where jobseeker_string = r.jobseeker_string ) as seeker_match,
count(1) / (select count(1) from Requirements where job_string = r.job_string) as job_match
from Requirements r
inner join Jobseeker j
on r.skill_string = j.r.skill_string
group by job_string, jobseeker_string;
select * from
(select
job_string,
jobseeker_string
count(1) / (select count(1) from Requirements where jobseeker_string = r.jobseeker_string ) as seeker_match,
count(1) / (select count(1) from Requirements where job_string = r.job_string) as job_match
from Requirements r
inner join Jobseeker j
on r.skill_string = j.r.skill_string
group by job_string, jobseeker_string) t
inner join applications a
on t.job_string = a.job_string and t.jobseeker_string = a.t.jobseeker_string
关于mysql - MATCH 多行与 SQL 查询中的多行并找到百分位数匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22750171/
我是一名优秀的程序员,十分优秀!