{"id":4638,"date":"2023-11-09T13:24:49","date_gmt":"2023-11-09T05:24:49","guid":{"rendered":"https:\/\/white-night.club\/?p=4638"},"modified":"2023-11-09T13:27:24","modified_gmt":"2023-11-09T05:27:24","slug":"ad140","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/09\/ad140\/","title":{"rendered":"1789.\u00a0\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8"},"content":{"rendered":"\n<p>\u8868\uff1a<code>Employee<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\u4e3a employee_id, department_id (\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408)\nemployee_id \u662f\u5458\u5de5\u7684ID\ndepartment_id \u662f\u90e8\u95e8\u7684ID\uff0c\u8868\u793a\u5458\u5de5\u4e0e\u8be5\u90e8\u95e8\u6709\u5173\u7cfb\nprimary_flag \u662f\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b\uff0c\u503c\u5206\u522b\u4e3a('Y', 'N'). \u5982\u679c\u503c\u4e3a'Y',\u8868\u793a\u8be5\u90e8\u95e8\u662f\u5458\u5de5\u7684\u76f4\u5c5e\u90e8\u95e8\u3002 \u5982\u679c\u503c\u662f'N',\u5219\u5426\n<\/pre>\n\n\n\n<p>\u4e00\u4e2a\u5458\u5de5\u53ef\u4ee5\u5c5e\u4e8e\u591a\u4e2a\u90e8\u95e8\u3002\u5f53\u4e00\u4e2a\u5458\u5de5\u52a0\u5165<strong>\u8d85\u8fc7\u4e00\u4e2a\u90e8\u95e8<\/strong>\u7684\u65f6\u5019\uff0c\u4ed6\u9700\u8981\u51b3\u5b9a\u54ea\u4e2a\u90e8\u95e8\u662f\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\u3002\u8bf7\u6ce8\u610f\uff0c\u5f53\u5458\u5de5\u53ea\u52a0\u5165\u4e00\u4e2a\u90e8\u95e8\u7684\u65f6\u5019\uff0c\u90a3\u8fd9\u4e2a\u90e8\u95e8\u5c06\u9ed8\u8ba4\u4e3a\u4ed6\u7684\u76f4\u5c5e\u90e8\u95e8\uff0c\u867d\u7136\u8868\u8bb0\u5f55\u7684\u503c\u4e3a<code>'N'<\/code>.<\/p>\n\n\n\n<p>\u8bf7\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u67e5\u51fa\u5458\u5de5\u6240\u5c5e\u7684\u76f4\u5c5e\u90e8\u95e8\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c&nbsp;<strong>\u6ca1\u6709\u987a\u5e8f\u8981\u6c42<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\u5b50\u6240\u793a\uff1a<\/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>\nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n- \u5458\u5de5 1 \u7684\u76f4\u5c5e\u90e8\u95e8\u662f 1\n- \u5458\u5de5 2 \u7684\u76f4\u5c5e\u90e8\u95e8\u662f 1\n- \u5458\u5de5 3 \u7684\u76f4\u5c5e\u90e8\u95e8\u662f 3\n- \u5458\u5de5 4 \u7684\u76f4\u5c5e\u90e8\u95e8\u662f 3<\/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>\u76f8\u5173\u5b50\u67e5\u8be2<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6bd4\u8f83\u7b80\u5355\u7684\u5b50\u67e5\u8be2\uff0c\u8fc7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\nSELECT A.employee_id,A.department_id\nFROM Employee AS A\nWHERE A.primary_flag='Y'\nOR NOT EXISTS(\n  SELECT 1\n  FROM Employee AS B \n  WHERE A.employee_id=B.employee_id\n  AND A.department_id!=B.department_id\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u76f8\u5173\u5b50\u67e5\u8be2<\/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\/4638"}],"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=4638"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4638\/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=4638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}