0

我在“用户”表中有这一行:

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)

谁能给我一个提示/提示?提前致谢。

4

2 回答 2

2

我想你想要这个功能year()

select year(birthdate) as birthyear, joined
from users
where year(birthdate) - joined >= 20
于 2013-02-20T20:15:11.117 回答
1

您可以使用该YEAR()函数获取年份值。然后要获得您想要的结果,您可以使用以下内容:

select year(birthdate), joined
from users 
where (joined - year(birthdate)) >= 20

请参阅带有演示的 SQL Fiddle

于 2013-02-20T20:16:18.603 回答