7 kyu
Extracting the Last Element from Concatenated Strings
197bornForThis
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 keytitle
: (string): Contains concatenated titles separated by '+'
Requirements:
- Write an SQL query to select each title from the
split_titles
table. - Extract and display the last element from each
title
after splitting it by the '+' character. - If the
title
does not contain the '+' symbol, display NULL as thelast_part
. - Order the results by the
id
column in descending order. - Your result set should include two columns:
- The original
title
. - The extracted last element or NULL, labeled as
last_part
.
- The original
Desired Output
The desired output should look like this:
title | last_part |
---|---|
HHHH | |
F+G+H+I | I |
D+EEE | EEE |
A+B+CC | CC |
SQL
Databases
Similar Kata:
Stats:
Created | Dec 29, 2023 |
Published | Dec 29, 2023 |
Warriors Trained | 335 |
Total Skips | 36 |
Total Code Submissions | 813 |
Total Times Completed | 197 |
SQL Completions | 197 |
Total Stars | 4 |
% of votes with a positive feedback rating | 96% of 24 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 7 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |