{ "data": { "question": { "questionId": "184", "questionFrontendId": "184", "categoryTitle": "Database", "boundTopicId": 1338, "title": "Department Highest Salary", "titleSlug": "department-highest-salary", "content": "
Table: Employee
\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| id | int |\n| name | varchar |\n| salary | int |\n| departmentId | int |\n+--------------+---------+\nid is the primary key (column with unique values) for this table.\ndepartmentId is a foreign key (reference columns) of the ID from the Department
table.\nEach row of this table indicates the ID, name, and salary of an employee. It also contains the ID of their department.\n
\n\n\n\n
Table: Department
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| id | int |\n| name | varchar |\n+-------------+---------+\nid is the primary key (column with unique values) for this table. It is guaranteed that department name is not NULL.
\nEach row of this table indicates the ID of a department and its name.\n
\n\n\n\n
Write a solution to find employees who have the highest salary in each of the departments.
\n\nReturn the result table in any order.
\n\nThe result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nEmployee table:\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 table:\n+----+-------+\n| id | name |\n+----+-------+\n| 1 | IT |\n| 2 | Sales |\n+----+-------+\nOutput: \n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT | Jim | 90000 |\n| Sales | Henry | 80000 |\n| IT | Max | 90000 |\n+------------+----------+--------+\nExplanation: Max and Jim both have the highest salary in the IT department and Henry has the highest salary in the Sales department.\n\n", "translatedTitle": "部门工资最高的员工", "translatedContent": "
表: Employee
\n+--------------+---------+\n| 列名 | 类型 |\n+--------------+---------+\n| id | int |\n| name | varchar |\n| salary | int |\n| departmentId | int |\n+--------------+---------+\n在 SQL 中,id是此表的主键。\ndepartmentId 是 Department 表中 id 的外键(在 Pandas 中称为 join key)。\n此表的每一行都表示员工的 id、姓名和工资。它还包含他们所在部门的 id。\n\n\n
\n\n
表: Department
\n+-------------+---------+\n| 列名 | 类型 |\n+-------------+---------+\n| id | int |\n| name | varchar |\n+-------------+---------+\n在 SQL 中,id 是此表的主键列。\n此表的每一行都表示一个部门的 id 及其名称。\n\n\n
\n\n
查找出每个部门中薪资最高的员工。
\n按 任意顺序 返回结果表。
\n查询结果格式如下例所示。
\n\n
示例 1:
\n\n\n输入:\nEmployee 表:\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 表:\n+----+-------+\n| id | name |\n+----+-------+\n| 1 | IT |\n| 2 | Sales |\n+----+-------+\n输出:\n+------------+----------+--------+\n| Department | Employee | Salary |\n+------------+----------+--------+\n| IT | Jim | 90000 |\n| Sales | Henry | 80000 |\n| IT | Max | 90000 |\n+------------+----------+--------+\n解释:Max 和 Jim 在 IT 部门的工资都是最高的,Henry 在销售部的工资最高。\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 685, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"191.5K\", \"totalSubmission\": \"369.7K\", \"totalAcceptedRaw\": 191476, \"totalSubmissionRaw\": 369662, \"acRate\": \"51.8%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"salary\", \"departmentId\"], \"Department\": [\"id\", \"name\"]}, \"rows\": {\"Employee\": [[1, \"Joe\", 70000, 1], [2, \"Jim\", 90000, 1], [3, \"Henry\", 80000, 2], [4, \"Sam\", 60000, 2], [5, \"Max\", 90000, 1]], \"Department\": [[1, \"IT\"], [2, \"Sales\"]]}}", "metaData": "{\"mysql\":[\"Create table If Not Exists Employee (id int, name varchar(255), salary int, departmentId int)\",\"Create table If Not Exists Department (id int, name varchar(255))\"],\"mssql\":[\"Create table Employee (id int, name varchar(255), salary int, departmentId int)\",\"Create table Department (id int, name varchar(255))\"],\"oraclesql\":[\"Create table Employee (id int, name varchar(255), salary int, departmentId int)\",\"Create table Department (id int, name varchar(255))\"],\"database\":true,\"name\":\"department_highest_salary\",\"pythondata\":[\"Employee = pd.DataFrame([], columns=['id', 'name', 'salary', 'departmentId']).astype({'id':'Int64', 'name':'object', 'salary':'Int64', 'departmentId':'Int64'})\",\"Department = pd.DataFrame([], columns=['id', 'name']).astype({'id':'Int64', 'name':'object'})\"],\"postgresql\":[\"Create table If Not Exists Employee (id int, name varchar(255), salary int, departmentId int)\",\"Create table If Not Exists Department (id int, name varchar(255))\"],\"database_schema\":{\"Employee\":{\"id\":\"INT\",\"name\":\"VARCHAR(255)\",\"salary\":\"INT\",\"departmentId\":\"INT\"},\"Department\":{\"id\":\"INT\",\"name\":\"VARCHAR(255)\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Employee (id int, name varchar(255), salary int, departmentId int)", "Create table If Not Exists Department (id int, name varchar(255))", "Truncate table Employee", "insert into Employee (id, name, salary, departmentId) values ('1', 'Joe', '70000', '1')", "insert into Employee (id, name, salary, departmentId) values ('2', 'Jim', '90000', '1')", "insert into Employee (id, name, salary, departmentId) values ('3', 'Henry', '80000', '2')", "insert into Employee (id, name, salary, departmentId) values ('4', 'Sam', '60000', '2')", "insert into Employee (id, name, salary, departmentId) values ('5', 'Max', '90000', '1')", "Truncate table Department", "insert into Department (id, name) values ('1', 'IT')", "insert into Department (id, name) values ('2', 'Sales')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"
\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"salary\", \"departmentId\"], \"Department\": [\"id\", \"name\"]}, \"rows\": {\"Employee\": [[1, \"Joe\", 70000, 1], [2, \"Jim\", 90000, 1], [3, \"Henry\", 80000, 2], [4, \"Sam\", 60000, 2], [5, \"Max\", 90000, 1]], \"Department\": [[1, \"IT\"], [2, \"Sales\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"