EasyNo. 2504LeetCode Premium
Concatenate the Name and the Profession — LeetCode 2504 Python Solution
- Topics
- Database
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | person_id | int | | name | varchar | | profession | ENUM | +-------------+---------+ person_id is the primary key (column with a unique value) for this table. Each row in this table contains a person's ID, name, and profession.Example
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| person_id | int |
| name | varchar |
| profession | ENUM |
+-------------+---------+
person_id is the primary key (column with a unique value) for this table.
Each row in this table contains a person's ID, name, and profession.
The profession column in an enum of the type ('Doctor', 'Singer', 'Actor', 'Player', 'Engineer', or 'Lawyer')Python solution
import duckdb
import pandas as pd
def solution(person: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Person", person)
return con.execute("""SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name
FROM Person
ORDER BY person_id DESC;""").df()Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 2504. Concatenate the Name and the Profession?
LeetCode 2504. Concatenate the Name and the Profession is rated Easy on LeetCode.
- What topics does LeetCode 2504. Concatenate the Name and the Profession cover?
LeetCode 2504. Concatenate the Name and the Profession is tagged Database on LeetCode.
- Is LeetCode 2504. Concatenate the Name and the Profession a premium problem?
Yes. LeetCode 2504. Concatenate the Name and the Profession is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.