一、查询数据
二、问题
41.按照出生日期来算,当前月日 < 出生年月的月日则,年龄减一
mysql> select student.SId as 学生编号,student.Sname as 学生姓名,
-> TIMESTAMPDIFF(YEAR,student.Sage,CURDATE()) as 学生年龄
-> from student;
+--------------+--------------+--------------+
| 学生编号 | 学生姓名 | 学生年龄 |
+--------------+--------------+--------------+
| 01 | 赵雷 | 33 |
| 02 | 钱电 | 32 |
| 03 | 孙风 | 32 |
| 04 | 李云 | 32 |
| 05 | 周梅 | 31 |
| 06 | 吴兰 | 31 |
| 07 | 郑竹 | 34 |
| 09 | 张三 | 5 |
| 10 | 李四 | 5 |
| 11 | 李四 | 11 |
| 12 | 赵六 | 10 |
| 13 | 孙七 | 9 |
+--------------+--------------+--------------+
12 rows in set (0.00 sec)
42.查询本周过生日的学生
mysql> select *
-> from student
-> where WEEKOFYEAR(student.Sage)=WEEKOFYEAR(CURDATE());
Empty set (0.00 sec)
43.查询下周过生日的学生
mysql> select *
-> from student
-> where WEEKOFYEAR(student.Sage)=WEEKOFYEAR(CURDATE())+1;
Empty set (0.00 sec)
44.查询本月过生日的学生
mysql> select *
-> from student
-> where MONTH(student.Sage)=MONTH(CURDATE());
Empty set (0.00 sec)
45.查询下月过生日的学生
mysql> select *
-> from student
-> where MONTH(student.Sage)=MONTH(CURDATE())+1;
Empty set (0.00 sec)