{ "data": { "question": { "questionId": "1509", "questionFrontendId": "1378", "categoryTitle": "Database", "boundTopicId": 145923, "title": "Replace Employee ID With The Unique Identifier", "titleSlug": "replace-employee-id-with-the-unique-identifier", "content": "
Table: Employees
\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.\nEach row of this table contains the id and the name of an employee in a company.\n\n\n
\n\n
Table: EmployeeUNI
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| unique_id | int |\n+---------------+---------+\n(id, unique_id) is the primary key (combination of columns with unique values) for this table.\nEach row of this table contains the id and the corresponding unique id of an employee in the company.\n\n\n
\n\n
Write a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null
.
Return the result table in any order.
\n\nThe result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nEmployees table:\n+----+----------+\n| id | name |\n+----+----------+\n| 1 | Alice |\n| 7 | Bob |\n| 11 | Meir |\n| 90 | Winston |\n| 3 | Jonathan |\n+----+----------+\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3 | 1 |\n| 11 | 2 |\n| 90 | 3 |\n+----+-----------+\nOutput: \n+-----------+----------+\n| unique_id | name |\n+-----------+----------+\n| null | Alice |\n| null | Bob |\n| 2 | Meir |\n| 3 | Winston |\n| 1 | Jonathan |\n+-----------+----------+\nExplanation: \nAlice and Bob do not have a unique ID, We will show null instead.\nThe unique ID of Meir is 2.\nThe unique ID of Winston is 3.\nThe unique ID of Jonathan is 1.\n\n", "translatedTitle": "使用唯一标识码替换员工ID", "translatedContent": "
Employees
表:
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| name | varchar |\n+---------------+---------+\n在 SQL 中,id 是这张表的主键。\n这张表的每一行分别代表了某公司其中一位员工的名字和 ID 。\n\n\n
\n\n
EmployeeUNI
表:
\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| unique_id | int |\n+---------------+---------+\n在 SQL 中,(id, unique_id) 是这张表的主键。\n这张表的每一行包含了该公司某位员工的 ID 和他的唯一标识码(unique ID)。\n\n\n
\n\n
展示每位用户的 唯一标识码(unique ID );如果某位员工没有唯一标识码,使用 null 填充即可。
\n\n你可以以 任意 顺序返回结果表。
\n\n返回结果的格式如下例所示。
\n\n\n\n
示例 1:
\n\n\n\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 60, "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 replace_employee_id(employees: pd.DataFrame, employee_uni: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"40K\", \"totalSubmission\": \"48.2K\", \"totalAcceptedRaw\": 39972, \"totalSubmissionRaw\": 48244, \"acRate\": \"82.9%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}", "metaData": "{\"mysql\":[\"Create table If Not Exists Employees (id int, name varchar(20))\",\"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"],\"mssql\":[\"Create table Employees (id int, name varchar(20))\",\"Create table EmployeeUNI (id int, unique_id int)\"],\"oraclesql\":[\"Create table Employees (id int, name varchar(20))\",\"Create table EmployeeUNI (id int, unique_id int)\"],\"database\":true,\"name\":\"replace_employee_id\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['id', 'name']).astype({'id':'int64', 'name':'object'})\",\"EmployeeUNI = pd.DataFrame([], columns=['id', 'unique_id']).astype({'id':'int64', 'unique_id':'int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Employees (id int, name varchar(20))\\n\",\"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"],\"database_schema\":{\"Employees\":{\"id\":\"INT\",\"name\":\"VARCHAR(20)\"},\"EmployeeUNI\":{\"id\":\"INT\",\"unique_id\":\"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Employees (id int, name varchar(20))", "Create table If Not Exists EmployeeUNI (id int, unique_id int)", "Truncate table Employees", "insert into Employees (id, name) values ('1', 'Alice')", "insert into Employees (id, name) values ('7', 'Bob')", "insert into Employees (id, name) values ('11', 'Meir')", "insert into Employees (id, name) values ('90', 'Winston')", "insert into Employees (id, name) values ('3', 'Jonathan')", "Truncate table EmployeeUNI", "insert into EmployeeUNI (id, unique_id) values ('3', '1')", "insert into EmployeeUNI (id, unique_id) values ('11', '2')", "insert into EmployeeUNI (id, unique_id) values ('90', '3')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"输入:\nEmployees
表:\n+----+----------+\n| id | name |\n+----+----------+\n| 1 | Alice |\n| 7 | Bob |\n| 11 | Meir |\n| 90 | Winston |\n| 3 | Jonathan |\n+----+----------+\nEmployeeUNI
表:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3 | 1 |\n| 11 | 2 |\n| 90 | 3 |\n+----+-----------+\n输出:\n+-----------+----------+\n| unique_id | name |\n+-----------+----------+\n| null | Alice |\n| null | Bob |\n| 2 | Meir |\n| 3 | Winston |\n| 1 | Jonathan |\n+-----------+----------+\n解释:\nAlice and Bob 没有唯一标识码, 因此我们使用 null 替代。\nMeir 的唯一标识码是 2 。\nWinston 的唯一标识码是 3 。\nJonathan 唯一标识码是 1 。
\\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\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"