0

我的任务是根据技能和可用性将我的数据库中的候选人与合适的职位空缺匹配,仅使用 sql 和 pl/sql。

我设法编写了以下代码,将可用的候选人与可用的空缺匹配。

 DECLARE
     CURSOR availableCandidates_cur IS
        SELECT * FROM candidate
        WHERE candidate.available = 'True';
     CURSOR availableJobs_cur IS
        SELECT *
        FROM position WHERE status = 'Open';
  BEGIN
      DBMS_OUTPUT.PUT_LINE('Available Candidates with matching vacencies');
      FOR availableCandidates_rec IN availableCandidates_cur
      LOOP
        DBMS_OUTPUT.PUT_LINE('Candidate: ' || availableCandidates_rec.firstName || ' ' ||  availableCandidates_rec.lastName);
        FOR availableJobs_rec IN availableJobs_cur
        LOOP
          IF (availableCandidates_rec.positionType = availableJobs_rec.positionType) THEN
            DBMS_OUTPUT.PUT_LINE(availableJobs_rec.positionName);
          END IF;
        END LOOP;
      END LOOP;
END;

我正在努力弄清楚如何根据匹配技能将候选人与职位匹配。有问题的表是

候选人技能

candidateID | skillID
1           | 2
1           | 3
2           | 1
3           | 1
3           | 3

岗位技能

positionID | skillID
1           | 1
1           | 3
2           | 1
3           | 2
3           | 3

所以例如我想输出那个

Candidate 1  Matches
position 3
Candidate 2 Matches
position 2
Candidate 3  Matches
position 2
position 3

我担心我最初可能走错了路,这导致了我的困惑。

如果有人能帮助我朝着正确的方向前进,我将不胜感激。

谢谢

4

2 回答 2

1

已更正。候选人 3 匹配工作 1 和 2,候选人 2 匹配工作 2,候选人 1 匹配工作 3

select distinct c.cid, j.jid 
from candidate c, jobs j
where j.sid=c.sid
and not exists
(select 'x' from jobs j2 where j2.jid=j.jid
and j2.sid not in (select c2.sid from candidate c2
where c2.cid=c.cid))
于 2012-04-18T20:39:15.237 回答
1
--All candidates that match every skill in a position
select distinct candidateID, positionID
from
(
    --Match candidates and positions, count number of skills that match
    select candidateID, positionID, skills_per_position
        ,count(*) over (partition by candidateID, positionID) matched_skills
    from candidateSkills
    inner join
    (
        --Number of skills per position
        select positionID, skillID
            ,count(*) over (partition by positionID) skills_per_position
        from positionSkills
        where status = 'Open'
    ) positionSkills_with_count
        on candidateSkills.skillID = positionSkills_with_count.skillID
    where available = 'True'
)
where matched_skills = skills_per_position
order by candidateID, positionID;

使用这些脚本构建表:

create table candidateSkills as
select 1 candidateid, 2 skillID, 'True' available from dual union all
select 1 candidateid, 3 skillID, 'True' available from dual union all
select 2 candidateid, 1 skillID, 'True' available from dual union all
select 3 candidateid, 1 skillID, 'True' available from dual union all
select 3 candidateid, 3 skillID, 'True' available from dual;

create table positionSkills as
select 1 positionID, 1 skillID, 'Open' status from dual union all
select 1 positionID, 3 skillID, 'Open' status from dual union all
select 2 positionID, 1 skillID, 'Open' status from dual union all
select 3 positionID, 2 skillID, 'Open' status from dual union all
select 3 positionID, 3 skillID, 'Open' status from dual;

但是,我的结果略有不同。候选人 3 匹配位置 1 和 2,而不是 2 和 3。我希望这只是您示例中的一个错字。

另外,我没有像你的那样格式化我的输出。让 SQL 以多行格式显示结果可能有点棘手。但是,如果您想在其他进程中使用它,不格式化 SQL 也会使其更有用。

于 2012-04-19T05:03:08.027 回答