참고 답변
You can split a single column into multiple columns using string functions like SUBSTRING
, SPLIT_PART
, or REGEXP
depending on your database.
Query (Using SPLIT_PART
) :
SELECT
SPLIT_PART(full_name, ' ', 1) AS first_name,
SPLIT_PART(full_name, ' ', 2) AS last_name
FROM users;
Alternative Query (Using SUBSTRING
and CHARINDEX
) :
For databases without SPLIT_PART
, you can use SUBSTRING
and CHARINDEX
(e.g., in SQL Server):
SELECT
SUBSTRING(full_name, 1, CHARINDEX(' ', full_name) - 1) AS first_name,
SUBSTRING(full_name, CHARINDEX(' ', full_name) + 1, LEN(full_name)) AS last_name
FROM users;
SPLIT_PART
: Splits the string based on a delimiter (e.g., space).SUBSTRING
: Extracts a portion of the string based on start and end positions.CHARINDEX
: Finds the position of the delimiter.