7 kyu

Extracting the Last Element from Concatenated Strings

Description:

Your task is to write an SQL query for a PostgreSQL database. The database includes a table named split_titles, which consists of titles as concatenated strings. Each string is comprised of elements separated exclusively by the '+' character. Your objective is to extract the last element from each concatenated string in the title column. If the title does not contain the '+' symbol, display NULL for the last part.

split_titles:

  • id (int): primary key
  • title: (string): Contains concatenated titles separated by '+'

Requirements:

  1. Write an SQL query to select each title from the split_titles table.
  2. Extract and display the last element from each title after splitting it by the '+' character.
  3. If the title does not contain the '+' symbol, display NULL as the last_part.
  4. Order the results by the id column in descending order.
  5. Your result set should include two columns:
    • The original title.
    • The extracted last element or NULL, labeled as last_part.

Desired Output

The desired output should look like this:

titlelast_part
HHHH
F+G+H+II
D+EEEEEE
A+B+CCCC
SQL
Databases

Stats:

CreatedDec 29, 2023
PublishedDec 29, 2023
Warriors Trained335
Total Skips36
Total Code Submissions813
Total Times Completed197
SQL Completions197
Total Stars4
% of votes with a positive feedback rating96% of 24
Total "Very Satisfied" Votes22
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments7
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad