{"id":2378,"date":"2023-10-12T09:39:49","date_gmt":"2023-10-12T01:39:49","guid":{"rendered":"https:\/\/white-night.club\/?p=2378"},"modified":"2023-11-09T11:07:50","modified_gmt":"2023-11-09T03:07:50","slug":"ad42","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/12\/ad42\/","title":{"rendered":"184.\u00a0\u90e8\u95e8\u5de5\u8d44\u6700\u9ad8\u7684\u5458\u5de5"},"content":{"rendered":"\n<p>\u8868\uff1a&nbsp;<code>Employee<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+--------------+---------+\n| \u5217\u540d          | \u7c7b\u578b    |\n+--------------+---------+\n| id           | int     |\n| name         | varchar |\n| salary       | int     |\n| departmentId | int     |\n+--------------+---------+\n\u5728 SQL \u4e2d\uff0cid\u662f\u6b64\u8868\u7684\u4e3b\u952e\u3002\ndepartmentId \u662f Department \u8868\u4e2d id \u7684\u5916\u952e\uff08\u5728 Pandas \u4e2d\u79f0\u4e3a join key\uff09\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u5458\u5de5\u7684 id\u3001\u59d3\u540d\u548c\u5de5\u8d44\u3002\u5b83\u8fd8\u5305\u542b\u4ed6\u4eec\u6240\u5728\u90e8\u95e8\u7684 id\u3002\n<\/pre>\n\n\n\n<p>\u8868\uff1a&nbsp;<code>Department<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| id          | int     |\n| name        | varchar |\n+-------------+---------+\n\u5728 SQL \u4e2d\uff0cid \u662f\u6b64\u8868\u7684\u4e3b\u952e\u5217\u3002\n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\u4e00\u4e2a\u90e8\u95e8\u7684 id \u53ca\u5176\u540d\u79f0\u3002\n<\/pre>\n\n\n\n<p>\u67e5\u627e\u51fa\u6bcf\u4e2a\u90e8\u95e8\u4e2d\u85aa\u8d44\u6700\u9ad8\u7684\u5458\u5de5\u3002<br>\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7ed3\u679c\u8868\u3002<br>\u67e5\u8be2\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\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\uff1a<\/strong>\nEmployee \u8868:\n+----+-------+--------+--------------+\n| id | name  | salary | departmentId |\n+----+-------+--------+--------------+\n| 1  | Joe   | 70000  | 1            |\n| 2  | Jim   | 90000  | 1            |\n| 3  | Henry | 80000  | 2            |\n| 4  | Sam   | 60000  | 2            |\n| 5  | Max   | 90000  | 1            |\n+----+-------+--------+--------------+\nDepartment \u8868:\n+----+-------+\n| id | name  |\n+----+-------+\n| 1  | IT    |\n| 2  | Sales |\n+----+-------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT         | Jim      | 90000  |\n| Sales      | Henry    | 80000  |\n| IT         | Max      | 90000  |\n+------------+----------+--------+\n<strong>\u89e3\u91ca\uff1a<\/strong>Max \u548c Jim \u5728 IT \u90e8\u95e8\u7684\u5de5\u8d44\u90fd\u662f\u6700\u9ad8\u7684\uff0cHenry \u5728\u9500\u552e\u90e8\u7684\u5de5\u8d44\u6700\u9ad8\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>\u591a\u8868\u67e5\u8be2<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5199\u4e86\u8fd9\u4e48\u591a\u7b80\u5355SQL\u9898\uff0c\u662f\u65f6\u5019\u52a0\u5165\u5c11\u8bb8\u4e2d\u7b49SQL\u9898\u7ed9\u81ea\u5df1\u4e0a\u4e0a\u5f3a\u5ea6\u4e86\u3002<\/p>\n\n\n\n<p>\u7ed9\u4e86\u4e24\u4e2a\u8868\uff0c\u5927\u6982\u7387\u662f\u8981\u4e24\u8868\u8fde\u7ed3\u4e86\u3002\u4e00\u770b\u6837\u4f8b\u8f93\u51fa\uff0c\u5176\u5b9e\u8981LEFT JOIN\uff0c\u90a3\u5148\u5199\u4e2a\u8fde\u7ed3\u770b\u770b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT Department.name,Employee.name,Salary\r\nFROM Department\r\nLEFT JOIN Employee\r\nON Employee.departmentId=Department.id<\/code><\/pre>\n\n\n\n<p>\u518d\u770b\u770b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>| Department | Employee | Salary |\r\n| ---------- | -------- | ------ |\r\n| IT         | Max      | 90000  |\r\n| IT         | Jim      | 90000  |\r\n| IT         | Joe      | 70000  |\r\n| Sales      | Sam      | 60000  |\r\n| Sales      | Henry    | 80000  |<\/code><\/pre>\n\n\n\n<p>\u548c\u6837\u4f8b\u8f93\u51fa\u7684\u683c\u5f0f\u8d77\u7801\u5bf9\u4e0a\u4e86\u3002\u63a5\u4e0b\u6765\u5224\u65ad\u6761\u4ef6\u3002<\/p>\n\n\n\n<p>\u6bcf\u4e2a\u90e8\u95e8\u4e2d\u94b1\u6700\u591a\u7684\uff0c\u5982\u679c\u5199\u6210\u5355\u4e2aSELECT\u90a3\u5c31\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT Employee.departmentId,MAX(Salary)\r\nFROM Employee\r\nGROUP BY Employee.departmentId<\/code><\/pre>\n\n\n\n<p>\u5b83\u7684\u8f93\u51fa\u5982\u4e0b\uff0c\u4e24\u4e2a\u6570\u636e\u5206\u522b\u662f\u4e0d\u540cdepartmentId\u4e2dsalary\u7684\u6700\u9ad8\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>| departmentId | MAX(Salary) |\r\n| ------------ | ----------- |\r\n| 1            | 90000       |\r\n| 2            | 80000       |<\/code><\/pre>\n\n\n\n<p>\u90a3\u5c31\u76f4\u63a5\u628a\u8fd9\u4e2aSELECT\u653e\u8fdb\u4e0a\u9762\u591a\u8868\u8fde\u7ed3\u7684where\u4e2d\uff0c\u4f5c\u4e3a\u67e5\u8be2\u6761\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT Department.name AS Department,Employee.name AS Employee,Salary\r\nFROM Department\r\nLEFT JOIN Employee\r\nON Employee.departmentId=Department.id\r\nWHERE (Employee.departmentId,Salary) in(\r\n  SELECT Employee.departmentId,MAX(Salary)\r\n  FROM Employee\r\n  GROUP BY Employee.departmentId\r\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u591a\u8868\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\/2378"}],"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=2378"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2378\/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=2378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}