Quick Overview

Write a SQL query that finds users whose comma-separated skills string contains Python as a complete skill, without matching names such as MicroPython or Python3. It tests token matching with anchored regular expressions or string splitting, along with NULL and empty-string handling.

Find users whose comma-separated skills list contains Python as a whole skill

Company: LinkedIn

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

`UserProfile` stores each user's skills as one comma-separated string, for example `'Java,Python,SQL'`. Find the users whose `skills` include `Python` as a complete skill. Substrings like `MicroPython` or `Python3` must not match. Return `user_id`, `name` and `skills`, ordered by `user_id` ascending. ```hint Token boundaries Think about what can sit immediately before and immediately after `Python` when it is a whole item in the list. ``` ### Input Table(s) `UserProfile` | Column | Type | Meaning | |---|---|---| | user_id | INT | The user | | name | VARCHAR(100) | The user's name | | skills | VARCHAR(500) | Comma-separated skill names, may be NULL or empty | Primary key: `user_id`. ### Output Contract | Column | Meaning | |---|---| | user_id | The matching user | | name | The user's name | | skills | The original `skills` string, unchanged | Return one row per matching user, ordered by `user_id` ascending. ### Example `UserProfile` | user_id | name | skills | |---|---|---| | 1 | Alice | Java,Python,SQL | | 2 | Bob | C++,Go | | 3 | Carol | Python | | 4 | Dave | MicroPython,Rust | | 5 | Eve | HTML,CSS,Python | Expected result: | user_id | name | skills | |---|---|---| | 1 | Alice | Java,Python,SQL | | 3 | Carol | Python | | 5 | Eve | HTML,CSS,Python | Alice has `Python` in the middle of her list, Carol has it as her only skill, and Eve has it last. Bob has no Python skill, and Dave's `MicroPython` only contains the text, so neither matches. ### Constraints and Clarifications - There are 1 to 10,000 users. - Skill names are alphanumeric, separated by commas with no spaces. - `skills` may be NULL or an empty string. Such users never match. - Skill names use consistent capitalization, so the skill always appears as `Python` and an exact, case-sensitive match is correct. - `user_id` is unique, so each matching user appears once in the output.

Overview: Write a SQL query that finds users whose comma-separated skills string contains Python as a complete skill, without matching names such as MicroPython or Python3. It tests token matching with anchored regular expressions or string splitting, along with NULL and empty-string handling.

The table `userprofile` stores each user's skills as one comma-separated string, for example `'Java,Python,SQL'`. Find the users whose `skills` include `Python` as a complete skill. Substrings like `MicroPython` or `Python3` must not match. Return `user_id`, `name` and `skills`, ordered by `user_id` ascending. ### Input Table `userprofile` | Column | Type | Meaning | |---|---|---| | user_id | INTEGER | The user | | name | VARCHAR(100) | The user's name | | skills | VARCHAR(500) | Comma-separated skill names, may be NULL or empty | Primary key: `user_id`. ### Output Contract | Column | Meaning | |---|---| | user_id | The matching user | | name | The user's name | | skills | The original `skills` string, unchanged | Return one row per matching user, ordered by `user_id` ascending. ### Example `userprofile` | user_id | name | skills | |---|---|---| | 1 | Alice | Java,Python,SQL | | 2 | Bob | C++,Go | | 3 | Carol | Python | | 4 | Dave | MicroPython,Rust | | 5 | Eve | HTML,CSS,Python | Expected result: | user_id | name | skills | |---|---|---| | 1 | Alice | Java,Python,SQL | | 3 | Carol | Python | | 5 | Eve | HTML,CSS,Python | Alice has `Python` in the middle of her list, Carol has it as her only skill, and Eve has it last. Bob has no Python skill, and Dave's `MicroPython` only contains the text, so neither matches. ### Constraints and Clarifications - There are 1 to 10,000 users. - Skill names are alphanumeric, separated by commas with no spaces. - `skills` may be NULL or an empty string. Such users never match. - Skill names use consistent capitalization, so the skill always appears as `Python` and an exact, case-sensitive match is correct. - `user_id` is unique, so each matching user appears once in the output.

Tables

userprofile(user_id INTEGER, name VARCHAR(100), skills VARCHAR(500))

Hints

  1. Think about what can sit immediately before and immediately after `Python` when it is a whole item in the list.
  2. A NULL or empty `skills` string has no items, so such a user never matches.
LinkedInData ScientisteasyData Manipulation (SQL/Python)

Users With Python as a Complete Skill

The table userprofile stores each user's skills as one comma-separated string, for example 'Java,Python,SQL'.

Find the users whose skills include Python as a complete skill. Substrings like MicroPython or Python3 must not match. Return user_id, name and skills, ordered by user_id ascending.

Input Table

userprofile

ColumnTypeMeaning
user_idINTEGERThe user
nameVARCHAR(100)The user's name
skillsVARCHAR(500)Comma-separated skill names, may be NULL or empty

Primary key: user_id.

Output Contract

ColumnMeaning
user_idThe matching user
nameThe user's name
skillsThe original skills string, unchanged

Return one row per matching user, ordered by user_id ascending.

Example

userprofile

user_idnameskills
1AliceJava,Python,SQL
2BobC++,Go
3CarolPython
4DaveMicroPython,Rust
5EveHTML,CSS,Python

Expected result:

user_idnameskills
1AliceJava,Python,SQL
3CarolPython
5EveHTML,CSS,Python

Alice has Python in the middle of her list, Carol has it as her only skill, and Eve has it last. Bob has no Python skill, and Dave's MicroPython only contains the text, so neither matches.

Constraints and Clarifications

  • There are 1 to 10,000 users.
  • Skill names are alphanumeric, separated by commas with no spaces.
  • skills may be NULL or an empty string. Such users never match.
  • Skill names use consistent capitalization, so the skill always appears as Python and an exact, case-sensitive match is correct.
  • user_id is unique, so each matching user appears once in the output.

Expected Output

Tables

userprofile
userprofile
ColumnType
user_idINTEGER
nameVARCHAR(100)
skillsVARCHAR(500)

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Run code to see results here.

Browse More Questions