2041. 面试中被录取的候选人 - 力扣(LeetCode)

  1. 2041. 面试中被录取的候选人 - 力扣(LeetCode)

  2. 目标

    1. 输入

      表:Candidates
      candidate_id name years_of_exp interview_id
      11 Atticus 1 101
      9 Ruben 6 104
      6 Aliza 10 109
      8 Alfredo 0 107
      表:Rounds
      interview_id round_id score
      109 3 4
      101 2 8
      109 4 1
      107 1 3
      104 3 6
      109 1 4
      104 4 7
      104 1 2
      109 2 1
      104 2 7
      107 2 3
      101 1 8
    2. 输出

      输出
      candidate_id
      9
  3. 分析

    编写解决方案,找出 至少有两年 工作经验、且面试分数之和 严格大于 15 的候选人的 ID 。
    表:Candidates 表:Rounds 输出
    candidate_id name years_of_exp interview_id interview_id round_id score candidate_id
    11 Atticus 1 101 109 3 4 9
    9 Ruben 6 104 101 2 8
    6 Aliza 10 109 109 4 1
    8 Alfredo 0 107 107 1 3
    104 3 6
    109 1 4
    104 4 7
    104 1 2
    109 2 1
    104 2 7
    107 2 3
    101 1 8
    筛选至少有两年经验的id,左连接ROUNDS表,分组聚合筛选面试分大于15的id candidate_id
    9
  4. 实现

    DROP TABLE IF EXISTS Candidates;
    DROP TABLE IF EXISTS Rounds;
    Create table If Not Exists Candidates (candidate_id int, name varchar(30), years_of_exp int, interview_id int);
    Create table If Not Exists Rounds (interview_id int, round_id int, score int);
    Truncate table Candidates;
    insert into Candidates (candidate_id, name, years_of_exp, interview_id) values ('11', 'Atticus', '1', '101');
    insert into Candidates (candidate_id, name, years_of_exp, interview_id) values ('9', 'Ruben', '6', '104');
    insert into Candidates (candidate_id, name, years_of_exp, interview_id) values ('6', 'Aliza', '10', '109');
    insert into Candidates (candidate_id, name, years_of_exp, interview_id) values ('8', 'Alfredo', '0', '107');
    Truncate table Rounds;
    insert into Rounds (interview_id, round_id, score) values ('109', '3', '4');
    insert into Rounds (interview_id, round_id, score) values ('101', '2', '8');
    insert into Rounds (interview_id, round_id, score) values ('109', '4', '1');
    insert into Rounds (interview_id, round_id, score) values ('107', '1', '3');
    insert into Rounds (interview_id, round_id, score) values ('104', '3', '6');
    insert into Rounds (interview_id, round_id, score) values ('109', '1', '4');
    insert into Rounds (interview_id, round_id, score) values ('104', '4', '7');
    insert into Rounds (interview_id, round_id, score) values ('104', '1', '2');
    insert into Rounds (interview_id, round_id, score) values ('109', '2', '1');
    insert into Rounds (interview_id, round_id, score) values ('104', '2', '7');
    insert into Rounds (interview_id, round_id, score) values ('107', '2', '3');
    insert into Rounds (interview_id, round_id, score) values ('101', '1', '8');
    SELECT * FROM Candidates;
    SELECT * FROM Rounds;
    # 筛选至少有两年经验的id,左连接ROUNDS表,分组聚合筛选面试分大于15的id
    SELECT candidate_id FROM Candidates
    LEFT JOIN Rounds R ON Candidates.interview_id = R.interview_id
    WHERE years_of_exp>=2
    GROUP BY candidate_id
    HAVING SUM(score)>15

  5. 小结

        左连接,分组聚合

你可能感兴趣的:(面试,职场和发展)