coops737
coops737

Reputation: 83

query adding and multiplying values

My table is as follows

int_id      Born         Died
 1          2001          0    
 2          2002          0    
 3          1991          0
 4          1992          0
 5          1987         1995
 6          1986         1993
 7          1985         1998

From this, I need the query to only show the dead, determine the age they were when they died and have that value multiplied by 3.

I have been trying to do this using phpMyAdmin but have thus far failed to figure it out. Any help given would be greatly appreciated.

Upvotes: 2

Views: 14001

Answers (1)

bfavaretto
bfavaretto

Reputation: 71918

Did you try, er... subtracting and multiplying?

SELECT 
    int_id,
    Died - Born AS age_died,
    3 * (Died - Born) AS age_died_tripled
FROM my_table
WHERE Died > 0;

Upvotes: 8

Related Questions