{"id":3894,"date":"2023-11-01T09:03:37","date_gmt":"2023-11-01T01:03:37","guid":{"rendered":"https:\/\/white-night.club\/?p=3894"},"modified":"2023-11-09T11:07:44","modified_gmt":"2023-11-09T03:07:44","slug":"ad117","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/01\/ad117\/","title":{"rendered":"185.&nbsp;\u90e8\u95e8\u5de5\u8d44\u524d\u4e09\u9ad8\u7684\u6240\u6709\u5458\u5de5"},"content":{"rendered":"\n<p>\u8868:&nbsp;<code>Employee<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| id           | int     |\n| name         | varchar |\n| salary       | int     |\n| departmentId | int     |\n+--------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\u5217(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217)\u3002\ndepartmentId \u662f Department \u8868\u4e2d ID \u7684\u5916\u952e\uff08reference \u5217\uff09\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u5458\u5de5\u7684ID\u3001\u59d3\u540d\u548c\u5de5\u8d44\u3002\u5b83\u8fd8\u5305\u542b\u4e86\u4ed6\u4eec\u90e8\u95e8\u7684ID\u3002\n<\/pre>\n\n\n\n<p>\u8868:&nbsp;<code>Department<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| name        | varchar |\n+-------------+---------+\nid \u662f\u8be5\u8868\u7684\u4e3b\u952e\u5217(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217)\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u90e8\u95e8ID\u548c\u90e8\u95e8\u540d\u3002\n<\/pre>\n\n\n\n<p>\u516c\u53f8\u7684\u4e3b\u7ba1\u4eec\u611f\u5174\u8da3\u7684\u662f\u516c\u53f8\u6bcf\u4e2a\u90e8\u95e8\u4e2d\u8c01\u8d5a\u7684\u94b1\u6700\u591a\u3002\u4e00\u4e2a\u90e8\u95e8\u7684&nbsp;<strong>\u9ad8\u6536\u5165\u8005<\/strong>&nbsp;\u662f\u6307\u4e00\u4e2a\u5458\u5de5\u7684\u5de5\u8d44\u5728\u8be5\u90e8\u95e8\u7684&nbsp;<strong>\u4e0d\u540c<\/strong>&nbsp;\u5de5\u8d44\u4e2d&nbsp;<strong>\u6392\u540d\u524d\u4e09<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u4e2d&nbsp;<strong>\u6536\u5165\u9ad8\u7684\u5458\u5de5<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7ed3\u679c\u8868\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165:<\/strong> \nEmployee \u8868:\n+----+-------+--------+--------------+\n| id | name  | salary | departmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 85000  | 1            |\n| 2  | Henry | 80000  | 2            |\n| 3  | Sam   | 60000  | 2            |\n| 4  | Max   | 90000  | 1            |\n| 5  | Janet | 69000  | 1            |\n| 6  | Randy | 85000  | 1            |\n| 7  | Will  | 70000  | 1            |\n+----+-------+--------+--------------+\nDepartment  \u8868:\n+----+-------+\n| id | name  |\n+----+-------+\n| 1  | IT    |\n| 2  | Sales |\n+----+-------+\n<strong>\u8f93\u51fa:<\/strong> \n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Max      | 90000  |\n| IT         | Joe      | 85000  |\n| IT         | Randy    | 85000  |\n| IT         | Will     | 70000  |\n| Sales      | Henry    | 80000  |\n| Sales      | Sam      | 60000  |\n+------------+----------+--------+\n<strong>\u89e3\u91ca:\n<\/strong>\u5728IT\u90e8\u95e8:\n- Max\u7684\u5de5\u8d44\u6700\u9ad8\n- \u5170\u8fea\u548c\u4e54\u90fd\u8d5a\u53d6\u7b2c\u4e8c\u9ad8\u7684\u72ec\u7279\u7684\u85aa\u6c34\n- \u5a01\u5c14\u7684\u85aa\u6c34\u662f\u7b2c\u4e09\u9ad8\u7684\n\n\u5728\u9500\u552e\u90e8:\n- \u4ea8\u5229\u7684\u5de5\u8d44\u6700\u9ad8\n- \u5c71\u59c6\u7684\u85aa\u6c34\u7b2c\u4e8c\u9ad8\n- \u6ca1\u6709\u7b2c\u4e09\u9ad8\u7684\u5de5\u8d44\uff0c\u56e0\u4e3a\u53ea\u6709\u4e24\u540d\u5458\u5de5<\/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>\u6d3e\u751f\u8868\u67e5\u8be2+\u7a97\u53e3\u51fd\u6570+\u5de6\u8054\u7ed3<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5237\u4e86\u4e00\u4e2a\u6708sql\u9898\uff0c\u7ec8\u4e8e\u505a\u51fa\u6765\u4e86\u7b2c\u4e00\u9053\u56f0\u96be\u9898\u3002\u4ee4\u4eba\u611f\u6168\uff0c\u5982\u6b64\u5982\u6b64\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"251\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/813f08ea96ca0cc6b7cdf6153e79d15.png\" alt=\"\" class=\"wp-image-3897\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/813f08ea96ca0cc6b7cdf6153e79d15.png 522w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/813f08ea96ca0cc6b7cdf6153e79d15-300x144.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/figure>\n\n\n\n<p>\u867d\u7136\u8fd9\u9053\u56f0\u96be\u9898\u5176\u5b9e&#8230;\u633a\u7b80\u5355\u7684\u3002\u6211\u7684\u601d\u8def\u662f\u5148\u5bf9Employee\u8868\u7b5b\u9009\uff0c\u6700\u540e\u5728\u5de6\u8054\u7ed3Department\u53bb\u5339\u914d\u90e8\u95e8\u7684name\u3002\u800c\u5148\u5bf9Employee\u8868\u7b5b\u9009\uff0c\u90a3\u4e48\u6211\u5f97\u7b5b\u9009\u51fa\u524d\u4e09\u9ad8\u7684rank\uff0c\u90a3\u6211\u9a6c\u4e0a\u5c31\u60f3\u5230\u4e86\u7a97\u53e3\u51fd\u6570\u3002\u518d\u770b\u4e0b\u6837\u4f8b\uff0c\u5bc6\u96c6\u6392\u5e8f\uff0c\u6240\u4ee5\u7528dense_rank\u3002<\/p>\n\n\n\n<p>\u4e0d\u5f97\u4e0d\u8bf4\u7a97\u53e3\u51fd\u6570\u6709\u70b9\u8fc7\u4e8e\u597d\u7528\u4e86\u3002\u5982\u679c\u4e0d\u7528\u7a97\u53e3\u51fd\u6570\u6211\u4e00\u65f6\u8fd8\u60f3\u4e0d\u51fa\u8be5\u600e\u4e48\u505a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\nSELECT B.name AS Department,A.name AS Employee,A.Salary\nFROM(\n  SELECT name,salary,departmentId,\n  dense_rank()over(partition by departmentId order by salary DESC) AS rk\n  FROM Employee\n)A\nLEFT JOIN Department AS B \nON A.departmentId=B.id\nWHERE rk=1 OR rk=2 OR rk=3\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u6d3e\u751f\u8868<\/p>\n","protected":false},"author":1,"featured_media":3897,"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\/3894"}],"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=3894"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3897"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}