首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用标准sql语句查询时间段的有关问题

2012-01-16 
用标准sql语句查询时间段的问题要查询在校时间超过三年的学生信息(其中enter_date的格式是2002-09-01这样

用标准sql语句查询时间段的问题
要查询在校时间超过三年的学生信息
(其中enter_date的格式是   2002-09-01这样的格式)

下面的语句有问题,请大家帮忙改一下?错在   'date '   不是可以识别的   函数名。
select   *   from   students   where(   year(   date()-year(enter_date)   )   )> 3

[解决办法]
select * from students where( year( getdate()-year(enter_date) ) )> 3

[解决办法]
晕,你的括号位置错了,应该是
select * from students where( year( getdate()) - year(enter_date) > 3)
[解决办法]

select datediff(year, '2005-01-02 ', getdate())

--result
-----------
2

(1 row(s) affected)

热点排行