{"id":2799,"date":"2023-10-18T08:52:44","date_gmt":"2023-10-18T00:52:44","guid":{"rendered":"https:\/\/white-night.club\/?p=2799"},"modified":"2023-11-09T11:07:48","modified_gmt":"2023-11-09T03:07:48","slug":"ad69","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/18\/ad69\/","title":{"rendered":"1077.\u00a0\u9879\u76ee\u5458\u5de5 III"},"content":{"rendered":"\n<p>\u9879\u76ee\u8868&nbsp;<code>Project<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408\uff09\nemployee_id \u662f\u5458\u5de5\u8868 Employee \u7684\u5916\u952e\uff08reference \u5217\uff09\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u660e\u5177\u6709 employee_id \u7684\u96c7\u5458\u6b63\u5728\u5904\u7406\u5177\u6709 project_id \u7684\u9879\u76ee\u3002\n<\/pre>\n\n\n\n<p>\u5458\u5de5\u8868&nbsp;<code>Employee<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id \u662f\u8fd9\u4e2a\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\uff09\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4e00\u540d\u96c7\u5458\u7684\u4fe1\u606f\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a\u5728\u6bcf\u4e00\u4e2a\u9879\u76ee\u4e2d&nbsp;<strong>\u7ecf\u9a8c\u6700\u4e30\u5bcc<\/strong>&nbsp;\u7684\u96c7\u5458\u662f\u8c01\u3002\u5982\u679c\u51fa\u73b0\u7ecf\u9a8c\u5e74\u6570\u76f8\u540c\u7684\u60c5\u51b5\uff0c\u8bf7\u62a5\u544a\u6240\u6709\u5177\u6709\u6700\u5927\u7ecf\u9a8c\u5e74\u6570\u7684\u5458\u5de5\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u8868&nbsp;<strong>\u65e0\u987a\u5e8f\u8981\u6c42 \u3002<\/strong><\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\u6240\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nProject \u8868\uff1a\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee \u8868\uff1a\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 3                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+-------------+---------------+\n| project_id  | employee_id   |\n+-------------+---------------+\n| 1           | 1             |\n| 1           | 3             |\n| 2           | 1             |\n+-------------+---------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>employee_id \u4e3a 1 \u548c 3 \u7684\u5458\u5de5\u5728 project_id \u4e3a 1 \u7684\u9879\u76ee\u4e2d\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002\u5728 project_id \u4e3a 2 \u7684\u9879\u76ee\u4e2d\uff0cemployee_id \u4e3a 1 \u7684\u5458\u5de5\u62e5\u6709\u6700\u4e30\u5bcc\u7684\u7ecf\u9a8c\u3002<\/pre>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>WHERE NOT EXISTS<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5199\u4e86\u51e0\u5341\u9053\u7b80\u5355SQL\u9898\uff0c\u6162\u6162\u5f00\u59cb\u52a0\u4e2d\u7b49\u9898\u611f\u53d7\u611f\u53d7\u4e86\u3002\u4e0d\u5f97\u4e0d\u8bf4\u4e2d\u7b49\u9898\u548c\u7b80\u5355\u9898\u771f\u7684\u662f\u6709\u660e\u663e\u7684\u5dee\u8ddd\u3002<\/p>\n\n\n\n<p>\u7a97\u53e3\u51fd\u6570\uff0c\u8fd8\u6ca1\u5b66\u5230\u3002\u518d\u4ed4\u7ec6\u770b\u770b\u9898\u76ee\uff0c\u4e00\u4e2aproject\u53ef\u80fd\u6709\u591a\u4e2a\u7b26\u5408\u6761\u4ef6\u7684employee\uff0c\u4e00\u4e2aemployee\u4e5f\u53ef\u80fd\u6709\u591a\u4e2a\u5339\u914d\u7684project\uff0c\u6240\u4ee5\u6211\u60f3\u7740\u7528\u4e0d\u4e86group by\uff0c\u90a3\u4e5f\u6ca1\u6cd5\u7528having\u3002\u90a3\u5c31\u5199\u4e2aWHERE EXISTS\u5b50\u67e5\u8be2\u5427\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote has-vivid-cyan-blue-color has-text-color\">\n<p>\u5199\u8005\u6ce8<\/p>\n<cite>\u6b64\u65f6\u7684\u6211\u8fd8\u6ca1\u7528\u8fc7in\uff0c\u6240\u4ee5\u81ea\u7136\u800c\u7136\u8fd9\u4e48\u60f3\u4e86\u3002\u5b9e\u9645\u4e0a\u8fd8\u662f\u53ef\u4ee5\u7528\u805a\u96c6\u51fd\u6570\u548cGROUP BY\u7684\uff0c\u800c\u4e14\u6bd4WHERE NOT EXISTS\u7b80\u77ed\u4e0d\u5c11\u3002<\/cite><\/blockquote>\n\n\n\n<p>\u4e00\u5f00\u59cb\u5199\u7684\u662fEXISTS\uff0c\u548c\u6211\u7684\u601d\u8def\u6bd4\u8f83\u7b26\u5408\u4e8e\u662f\u70b9\u4e86\u63d0\u4ea4\uff0c\u53d1\u73b0\u53ea\u80fd\u8fc7\u7b2c\u4e00\u4e2a\u6837\u4f8b\u3002\u90a3\u518d\u4ed4\u7ec6\u89c2\u5bdf\u89c2\u5bdf\uff0c\u5982\u679cB\u7684\u7ecf\u9a8c\u5927\u4e8e\u7b49\u4e8eD\u7684\u7ecf\u9a8c\uff0c\u5b83\u4f1a\u9a6c\u4e0a\u8fd4\u56de\u5417\uff1f\u5e76\u4e0d\u4f1a\u3002<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">EXISTS\u8868\u793a\u7684\u662f\u201c\u5b58\u5728<\/mark>\u201d\u3002\u8bf4\u660e\u53ea\u8981\u6709\u5927\u4e8e\u7b49\u4e8e\u7684\u60c5\u51b5\u53d1\u751f\uff0c\u5b83\u5c31\u4f1a\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u800c\u6211\u4eec\u8981\u7684\u662f\u6700\u5927\u7684\uff0c\u90a3\u4e48\u7528NOT EXISTS\u4e0d\u5c31\u597d\u4e86\uff1f\u7528\u4e8e\u8868\u793a\u4e0d\u5b58\u5728\u5c0f\u4e8exxx\u7ecf\u9a8c\u7684\u60c5\u51b5\u51fa\u73b0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.project_id,B.employee_id\r\nFROM Project AS A \r\nLEFT JOIN Employee AS B \r\nON A.employee_id=B.employee_id\r\nWHERE NOT EXISTS(\r\n  SELECT C.*,D.* FROM Project AS C,Employee AS D \r\n  WHERE C.employee_id=D.employee_id AND C.project_id=A.project_id\r\n  AND B.experience_years&lt;D.experience_years \r\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u76f8\u5173\u5b50\u67e5\u8be2WHERE NOT EXISTS<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2799"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2799"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2799\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}