Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.
Extract Characters From Strings
Create Table
-- Create table called adventurers
CREATE TABLE adventurers (
-- string variable
name varchar(255),
-- integer variable
age int,
-- string variable
race varchar(255),
-- string variable
weapon varchar(255)
)
Insert Rows
-- Insert into the table adventurers
INSERT INTO adventurers (name, age, race, weapon)
VALUES ('Fjoak Doom-Wife', 28, 'Human', 'Axe'),
('Alooneric Cortte', 29, 'Human', 'Bow'),
('Piperel Ramsay', 35, 'Elf', 'Bow'),
('Casimir Yardley', 14, 'Elf', 'Bow')
Extract Characters From Strings
-- Extract the first two characters from the race column values
SELECT name, age, SUBSTR(race, 1, 2) FROM adventurers
name | age | substr |
---|---|---|
Fjoak Doom-Wife | 28 | Hu |
Alooneric Cortte | 29 | Hu |
Piperel Ramsay | 35 | El |
Casimir Yardley | 14 | El |