准备数据:
1、查询各学生的年龄,只按年份来算
select Sname,year(now())-year(Sage) as age from student;
==
学习写法:
select
*,
year(now())-year(sage) as age
from student;
2、按照出生日期来算,当前月日 < 出生年月的月日则,年龄减一
select SId ,Sname,timestampdiff(year,Sage,now()) as age from student;
3、查询本周过生日的学生
思考过程:
查找现在是哪一周?
学生生日是哪一周?
判断二者是否相等?
select * from student where week(Sage)=week(now());
网友评论