Mathematical Operations On Columns

Create Table Of Adventurers

-- Create table called adventurers
CREATE TABLE adventurers (
    -- string variable
    name varchar(255),
    -- integer variable
    age int,
    -- string variable
    race varchar(255)
)

Insert Rows

-- Insert into the table adventurers
INSERT INTO adventurers (name, age, race)
VALUES ('Fjoak Doom-Wife', 28, 'Human'),
       ('Alooneric Cortte', 29, 'Elf'),
       ('Piperel Ramsay', 35, 'Elf'),
       ('Casimir Yardley', 14, 'Elf')

Apply Addition To Column

-- Apply operation
UPDATE adventurers SET age = age + 10

View Table

-- Retrieve data
SELECT * FROM adventurers
nameagerace
Fjoak Doom-Wife38Human
Alooneric Cortte39Elf
Piperel Ramsay45Elf
Casimir Yardley24Elf

Apply Substraction To Column

-- Apply operation
UPDATE adventurers SET age = age - 10

View Table

-- Retrieve data
SELECT * FROM adventurers
nameagerace
Fjoak Doom-Wife28Human
Alooneric Cortte29Elf
Piperel Ramsay35Elf
Casimir Yardley14Elf

Apply Multiplication To Column

-- Apply operation
UPDATE adventurers SET age = age * 10

View Table

-- Retrieve data
SELECT * FROM adventurers
nameagerace
Fjoak Doom-Wife280Human
Alooneric Cortte290Elf
Piperel Ramsay350Elf
Casimir Yardley140Elf

Apply Division To Column

-- Apply operation
UPDATE adventurers SET age = age / 10

View Table

-- Retrieve data
SELECT * FROM adventurers
nameagerace
Fjoak Doom-Wife28Human
Alooneric Cortte29Elf
Piperel Ramsay35Elf
Casimir Yardley14Elf

Apply Modulo To Column

-- Apply operation
UPDATE adventurers SET age = age % 10

View Table

-- Retrieve data
SELECT * FROM adventurers
nameagerace
Fjoak Doom-Wife8Human
Alooneric Cortte9Elf
Piperel Ramsay5Elf
Casimir Yardley4Elf