我想获得所有生日是下个月的学生(我已经看过几个答案)只过滤那些将要 21 岁的学生,知道吗?我的表名是students
,列名是birthdate
(日期),谢谢!
问问题
320 次
3 回答
2
如果生日是日期类型,您可以使用如下内容:
SELECT *
FROM students
WHERE
birthdate BETWEEN
LAST_DAY(CURDATE())+INTERVAL 1 DAY - INTERVAL 21 YEAR AND
LAST_DAY(LAST_DAY(CURDATE())+INTERVAL 1 DAY) - INTERVAL 21 YEAR
于 2013-04-10T19:50:13.043 回答
2
假设生日列是日期类型,您可以使用如下条件过滤掉 20 岁且下个月过生日的学生。
SELECT * FROM students
WHERE MONTH(birthdate) = (MONTH(NOW()) % 12) + 1
AND
TIMESTAMPDIFF(YEAR, birthdate, NOW()) = 20
于 2013-04-10T19:50:25.460 回答
0
Try this:
SELECT * FROM students WHERE MONTH(birthdate)=(MONTH(CURDATE()) % 12 + 1) AND
(YEAR(CURDATE())-YEAR(birthdate) = 21) ;
于 2013-04-10T20:06:52.957 回答