查询添加和乘以值

时间:2012-05-01 04:33:19

标签: mysql

我的表格如下

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

由此,我需要查询只显示死者,确定死亡时的年龄,并将该值乘以3。

我一直在尝试使用phpMyAdmin做到这一点,但迄今为止未能弄明白。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:5)

你有没有尝试过,呃...减去和倍增?

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