我必须计算死亡的马的年龄,multiply by 3
以获得可比的人类年龄。列出他们的horse_id,名称和human years
,按horse_id
排序。
我是一个菜鸟,只是无法理解我需要做什么,在网上看这是我能得到的最接近的,Born和Died列是日期,但只有一年。
任何帮助都将不胜感激。
SELECT Horse_id, name, Born, Died,
TIMESTAMPDIFF(YEAR, Died, Born)*3 AS 'Human Years'
FROM horsedb.horse
ORDER BY Horse_id;
答案 0 :(得分:0)
你的尝试看起来很好 - 你从中获得了什么结果?这是我会尝试的:
SELECT Horse_id, name, Born, Died,
(YEAR(Died) - YEAR(Born)) * 3 AS 'Human Years'
FROM horsedb.horse
ORDER BY Horse_id;
答案 1 :(得分:0)
我会在几个月内完成计算。 。 。将月数除以4.这是一种方法:
SELECT Horse_id, name, Born, Died,
FLOOR( (YEAR(Died)*12 + MONTH(Died)) - (YEAR(Born)*12 + Month(Born)) / 4) as HumanYears
FROM horsedb.horse
ORDER BY Horse_id;