Calculate Time Duration

Create Table

-- Create table called dead_adventurers
CREATE TABLE dead_adventurers (
    -- string variable
    name varchar(255),
    -- string variable
    race varchar(255),
    -- string variable
    weapon varchar(255),
    -- date variable
    started_adventure date,
    -- date variable
    died date
)

Insert Rows

-- Insert into the table dead_adventurers
INSERT INTO dead_adventurers (name, race, weapon, started_adventure, died)
VALUES ('Fjoak Doom-Wife', 'Human', 'Axe', '09-JAN-2017', '10-Nov-2017'),
       ('Alooneric Cortte', 'Elf', 'Bow', '10-JAN-2017', '11-JAN-2017'),
       ('Piperel Ramsay', 'Elf', 'Sword', '11-JAN-2017', '12-APR-2017'),
       ('Casimir Yardley', 'Elf', 'Magic', '23-JAN-2017', '06-MAY-2017')

Calculate Duration Between Two Date Values

-- Get all the columns, and add a new column called days_on_adventure
-- that is the number of days between the start of the adventurer and when they died
SELECT *, died - started_adventure AS days_on_adventure FROM dead_adventurers
nameraceweaponstarted_adventuredieddays_on_adventure
Fjoak Doom-WifeHumanAxe2017-01-092017-11-10305
Alooneric CortteElfBow2017-01-102017-01-111
Piperel RamsayElfSword2017-01-112017-04-1291
Casimir YardleyElfMagic2017-01-232017-05-06103