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/the-number-of-employees-which-report-to-each-employee.json
2023-12-09 19:57:46 +08:00

91 lines
9.4 KiB
JSON
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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": "1882",
"questionFrontendId": "1731",
"categoryTitle": "Database",
"boundTopicId": 572194,
"title": "The Number of Employees Which Report to Each Employee",
"titleSlug": "the-number-of-employees-which-report-to-each-employee",
"content": "<p>Table: <code>Employees</code></p>\n\n<pre>\n+-------------+----------+\n| Column Name | Type |\n+-------------+----------+\n| employee_id | int |\n| name | varchar |\n| reports_to | int |\n| age | int |\n+-------------+----------+\nemployee_id is the column with unique values for this table.\nThis table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). \n</pre>\n\n<p>&nbsp;</p>\n\n<p>For this problem, we will consider a <strong>manager</strong> an employee who has at least 1 other employee reporting to them.</p>\n\n<p>Write a solution to report the ids and the names of all <strong>managers</strong>, the number of employees who report <strong>directly</strong> to them, and the average age of the reports rounded to the nearest integer.</p>\n\n<p>Return the result table ordered by <code>employee_id</code>.</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> \nEmployees table:\n+-------------+---------+------------+-----+\n| employee_id | name | reports_to | age |\n+-------------+---------+------------+-----+\n| 9 | Hercy | null | 43 |\n| 6 | Alice | 9 | 41 |\n| 4 | Bob | 9 | 36 |\n| 2 | Winston | null | 37 |\n+-------------+---------+------------+-----+\n<strong>Output:</strong> \n+-------------+-------+---------------+-------------+\n| employee_id | name | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9 | Hercy | 2 | 39 |\n+-------------+-------+---------------+-------------+\n<strong>Explanation:</strong> Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.\n</pre>\n",
"translatedTitle": "每位经理的下属员工数量",
"translatedContent": "<p>Table: <code>Employees</code></p>\n\n<pre>+-------------+----------+\n| Column Name | Type |\n+-------------+----------+\n| employee_id | int |\n| name | varchar |\n| reports_to | int |\n| age | int |\n+-------------+----------+\nemployee_id 是这个表的主键.\n该表包含员工以及需要听取他们汇报的上级经理的ID的信息。 有些员工不需要向任何人汇报reports_to 为空)。\n</pre>\n\n<p> </p>\n\n<p>对于此问题,我们将至少有一个其他员工需要向他汇报的员工,视为一个经理。</p>\n\n<p>编写SQL查询需要听取汇报的所有经理的ID、名称、直接向该经理汇报的员工人数以及这些员工的平均年龄其中该平均年龄需要四舍五入到最接近的整数。</p>\n\n<p>返回的结果集需要按照 <code>employee_id </code>进行排序。</p>\n\n<p>查询结果的格式如下:</p>\n\n<p> </p>\n\n<pre>Employees table:\n+-------------+---------+------------+-----+\n| employee_id | name | reports_to | age |\n+-------------+---------+------------+-----+\n| 9 | Hercy | null | 43 |\n| 6 | Alice | 9 | 41 |\n| 4 | Bob | 9 | 36 |\n| 2 | Winston | null | 37 |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9 | Hercy | 2 | 39 |\n+-------------+-------+---------------+-------------+\nHercy 有两个需要向他汇报的员工, 他们是 Alice and Bob. 他们的平均年龄是 (41+36)/2 = 38.5, 四舍五入的结果是 39.\n</pre>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 46,
"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 count_employees(employees: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"19.1K\", \"totalSubmission\": \"41.4K\", \"totalAcceptedRaw\": 19145, \"totalSubmissionRaw\": 41425, \"acRate\": \"46.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"mssql\":[\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"oraclesql\":[\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"database\":true,\"name\":\"count_employees\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['employee_id', 'name', 'reports_to', 'age']).astype({'employee_id':'Int64', 'name':'object', 'reports_to':'Int64', 'age':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"database_schema\":{\"Employees\":{\"employee_id\":\"INT\",\"name\":\"VARCHAR(20)\",\"reports_to\":\"INT\",\"age\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)",
"Truncate table Employees",
"insert into Employees (employee_id, name, reports_to, age) values ('9', 'Hercy', 'None', '43')",
"insert into Employees (employee_id, name, reports_to, age) values ('6', 'Alice', '9', '41')",
"insert into Employees (employee_id, name, reports_to, age) values ('4', 'Bob', '9', '36')",
"insert into Employees (employee_id, name, reports_to, age) values ('2', 'Winston', 'None', '37')"
],
"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\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}",
"__typename": "QuestionNode"
}
}
}