We have started working with functions to manipulate strings.
SELECT phone AS original_phone, -- from `8005551205` to `(800) 555-1205` LEFT(phone, 3) AS area_code, -- extracting `800` SUBSTRING(phone, 4, 3) AS branch_exchange, -- extracting `555` RIGHT(phone, 4) AS subscriber_number, -- extracting `1205` CONCAT ( -- concatenating values 1 to 6 `(`, -- value 1, hard-coded the opening parenthesis LEFT(phone, 3), -- value 2, area code from `phone` `) `, -- value 3, hard-coded closing parenthesis + space SUBSTRING(phone, 4, 3), -- value 4, branch from `phone` ` - `, -- value 5, hard-coded hyphen RIGHT(phone, 4) -- value 6, subscriber number from `phone` ) AS legible_phone FROM table1;
Download the class notes for day 3.