设置包含在SQL中

时间:2019-07-15 20:36:08

标签: sql postgresql

任务是检查一组是否完全包含另一组。作为简化示例,我们可以采用四个表:

  • public class QuickCopy extends Application { @Override public void start(Stage stage) throws Exception { FXMLLoader loader = new FXMLLoader(getClass().getResource("Main.fxml")); AnchorPane root = (AnchorPane)loader.load(); Scene scene = new Scene(root); stage.setScene(scene); stage.sizeToScene(); stage.setResizable(false); stage.show(); MainController controller = (MainController)loader.getController(); controller.sendScene(scene); System.out.println("new: " +scene.lookup("selectorontop")); } (ID,名称),
  • worker(worker_id,技能),
  • worker_skills(id,类型)
  • job(job_id,技能)

我想使工人与工作匹配,但前提是工作所需的技能与工人的技能完全匹配,即e。如果工人具有一些工作中不需要的技能,那没关系,但是如果工作中至少有一个工人没有的技能,那么他们就不匹配。

我能想到的所有内容都包括大量的联接,不能用作严肃的解决方案,因此,任何建议都将受到高度赞赏。数据库是postgres 9.6。谢谢!

编辑: 一些样本数据:

job_required_skills

结果:

+------+---------------+
| name | worker_skills |
+------+---------------+
| John | java          |
| John | sql           |
| John | ruby          |
| Jane | js            |
| Jane | html          |
+------+---------------+

+---------------------+-------------+
|        type         | job_skills  |  
+---------------------+-------------+
| Writing_queries     | sql         |  
| Writing_queries     | black_magic |  
| Generic_programming | java        |    
| Frontend_stuff      | js          |  
| Frontend_stuff      | html        | 
+---------------------+-------------+

John完全具备+------+---------------------+ | John | Generic_programming | +------+---------------------+ | Jane | Frontend_stuff | +------+---------------------+ 的资格(唯一需要的技能是他的技能),却不能Generic_programming,因为它需要一些Writing_queries;简可以同时做black_magic,因为她同时具备两种技能。

1 个答案:

答案 0 :(得分:1)

您可以使用left join和聚合:

select jrs.id, ws.id
from job_required_skills jrs left join
     worker_skills ws
     on jrs.skill = ws.skill
group by jrs.id, ws.id
having count(*) = count(ws.skill)