MySQL查询以获取显示学生的出生日期的记录范围之间的日期?
要在日期之间获取记录,请使用BETWEEN。让我们首先创建一个表-
mysql> create table DemoTable863(StudentDateOfBirth date);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable863 values('1998-01-10');
mysql> insert into DemoTable863 values('2000-10-15');
mysql> insert into DemoTable863 values('2003-04-20');
mysql> insert into DemoTable863 values('2005-12-31');
mysql> insert into DemoTable863 values('1999-07-01');使用select语句显示表中的所有记录-
mysql> select *from DemoTable863;
这将产生以下输出-
+--------------------+ | StudentDateOfBirth | +--------------------+ | 1998-01-10 | | 2000-10-15 | | 2003-04-20 | | 2005-12-31 | | 1999-07-01 | +--------------------+ 5 rows in set (0.00 sec)
以下是查询以显示基于DOB的范围内的日期,即20AND21-
mysql> select *from DemoTable863 where (YEAR(NOW()) - YEAR(StudentDateOfBirth)) BETWEEN 20 AND 21;
这将产生以下输出-
+--------------------+ | StudentDateOfBirth | +--------------------+ | 1998-01-10 | | 1999-07-01 | +--------------------+ 2 rows in set (0.03 sec)
热门推荐
10 高考毕业祝福语简短励志
11 简短古文生日祝福语
12 诗意新婚祝福语高级简短
13 新年恋人祝福语简短创意
14 开业祝福语简短大气的
15 新大学开学祝福语简短
16 生日祝福语简短明了 同事
17 生日祝福语男孩 简短独特
18 步入高中祝福语简短励志