我在“用户”表中有这一行:
id = 1;
birthdate(date) = 1992-02-12;
joined(int) = 2000;
我想创建这样的东西:
SELECT
CAST(birthdate as INT(4)) as birthyear, joined
FROM
users
WHERE
(birthyear - joined >= 20)
谁能给我一个提示/提示?提前致谢。
我想你想要这个功能year()
:
select year(birthdate) as birthyear, joined
from users
where year(birthdate) - joined >= 20
您可以使用该YEAR()
函数获取年份值。然后要获得您想要的结果,您可以使用以下内容:
select year(birthdate), joined
from users
where (joined - year(birthdate)) >= 20