1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/primary-department-for-each-employee.json
2023-12-09 19:57:46 +08:00

94 lines
11 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "1942",
"questionFrontendId": "1789",
"categoryTitle": "Database",
"boundTopicId": 654757,
"title": "Primary Department for Each Employee",
"titleSlug": "primary-department-for-each-employee",
"content": "<p>Table: <code>Employee</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| employee_id | int |\n| department_id | int |\n| primary_flag | varchar |\n+---------------+---------+\n(employee_id, department_id) is the primary key (combination of columns with unique values) for this table.\nemployee_id is the id of the employee.\ndepartment_id is the id of the department to which the employee belongs.\nprimary_flag is an ENUM (category) of type (&#39;Y&#39;, &#39;N&#39;). If the flag is &#39;Y&#39;, the department is the primary department for the employee. If the flag is &#39;N&#39;, the department is not the primary.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is <code>&#39;N&#39;</code>.</p>\n\n<p>Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</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>Output:</strong> \n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 3 |\n| 4 | 3 |\n+-------------+---------------+\n<strong>Explanation:</strong> \n- The Primary department for employee 1 is 1.\n- The Primary department for employee 2 is 1.\n- The Primary department for employee 3 is 3.\n- The Primary department for employee 4 is 3.\n</pre>\n",
"translatedTitle": "员工的直属部门",
"translatedContent": "<p>表:<code>Employee</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| employee_id | int |\n| department_id | int |\n| primary_flag | varchar |\n+---------------+---------+\n这张表的主键为 employee_id, department_id (具有唯一值的列的组合)\nemployee_id 是员工的ID\ndepartment_id 是部门的ID表示员工与该部门有关系\nprimary_flag 是一个枚举类型,值分别为('Y', 'N'). 如果值为'Y',表示该部门是员工的直属部门。 如果值是'N',则否\n</pre>\n\n<p>&nbsp;</p>\n\n<p>一个员工可以属于多个部门。当一个员工加入<strong>超过一个部门</strong>的时候,他需要决定哪个部门是他的直属部门。请注意,当员工只加入一个部门的时候,那这个部门将默认为他的直属部门,虽然表记录的值为<code>'N'</code>.</p>\n\n<p>请编写解决方案,查出员工所属的直属部门。</p>\n\n<p>返回结果 <strong>没有顺序要求</strong> 。</p>\n\n<p>返回结果格式如下例子所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</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>输出:</strong>\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 3 |\n| 4 | 3 |\n+-------------+---------------+\n<strong>解释:</strong>\n- 员工 1 的直属部门是 1\n- 员工 2 的直属部门是 1\n- 员工 3 的直属部门是 3\n- 员工 4 的直属部门是 3</pre>\n\n<p>&nbsp;</p>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 44,
"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 find_primary_department(employee: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"15.3K\", \"totalSubmission\": \"22.9K\", \"totalAcceptedRaw\": 15325, \"totalSubmissionRaw\": 22867, \"acRate\": \"67.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))\"],\"mssql\":[\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"],\"oraclesql\":[\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"],\"database\":true,\"name\":\"find_primary_department\",\"pythondata\":[\"Employee = pd.DataFrame([], columns=['employee_id', 'department_id', 'primary_flag']).astype({'employee_id':'Int64', 'department_id':'Int64', 'primary_flag':'object'})\"],\"postgresql\":[\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag VARCHAR(30) CHECK (primary_flag IN ('Y','N')))\\n\"],\"database_schema\":{\"Employee\":{\"employee_id\":\"INT\",\"department_id\":\"INT\",\"primary_flag\":\"ENUM('Y', 'N')\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))",
"Truncate table Employee",
"insert into Employee (employee_id, department_id, primary_flag) values ('1', '1', 'N')",
"insert into Employee (employee_id, department_id, primary_flag) values ('2', '1', 'Y')",
"insert into Employee (employee_id, department_id, primary_flag) values ('2', '2', 'N')",
"insert into Employee (employee_id, department_id, primary_flag) values ('3', '3', 'N')",
"insert into Employee (employee_id, department_id, primary_flag) values ('4', '2', 'N')",
"insert into Employee (employee_id, department_id, primary_flag) values ('4', '3', 'Y')",
"insert into Employee (employee_id, department_id, primary_flag) values ('4', '4', 'N')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}",
"__typename": "QuestionNode"
}
}
}