select YEAR(birthdate),firstname,lastname from HR.Employees where YEAR(birthdate)='1973'
其中Year(birthdate),其中Year为sql的内置函数。当然也可以用于对字符串日期进行取出年份的计算。同时我们还可以采用下面的sql语句进行查询:
select YEAR(birthdate),firstname,lastname from HR.Employees where birthdate>'1973-01-01' and birthdate<'1974-12-31'
查询条件带计算列走的是索引扫描,而where子句后面采用查找范围限制,则走的是索查找。
走索引查找的查询性能要高于走索引扫描,特别是查询的数据库不是非常大的情况下,索引查找的消耗时间要远远少于索引扫描的时间。所以在查询条件中尽量避免计算条件。