为此,请YEAR()
按照以下语法使用MySQL-
select * from yourTableName where year(yourColumnName)=’yourYearValue’;
让我们首先创建一个表-
mysql> create table DemoTable1322 -> ( -> DOB date -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1322 values('1999-04-12'); mysql> insert into DemoTable1322 values('2010-12-01'); mysql> insert into DemoTable1322 values('2015-03-09'); mysql> insert into DemoTable1322 values('2007-05-24');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1322;
输出结果
+------------+ | DOB | +------------+ | 1999-04-12 | | 2010-12-01 | | 2015-03-09 | | 2007-05-24 | +------------+ 4 rows in set (0.00 sec)
这是yyyy-mm-dd结构中要搜索的dob的查询。我们正在与yyyy进行比较,即特定年份-
mysql> select * from DemoTable1322 where year(DOB)='2015';
输出结果
+------------+ | DOB | +------------+ | 2015-03-09 | +------------+ 1 row in set (0.01 sec)