SQL中,如何查询年龄

来源:百度知道 编辑:UC知道 时间:2024/05/28 18:48:24
出生日期
1989
1986
1983
1978
查询年龄在20-25岁之间的学生的年龄

日期函数,access与SQL Server是有一点区别的,
如果是access的话,
select * from 你的表名
where year(now())-year(出生日期) between 20 and 25
如果是SQL Server的话,
select * from 你的表名
where year(getdate())-year(出生日期) between 20 and 25
呵呵,希望能有帮助,^_^

select * from 你的表名
where year(getdate())-year(出生日期) between 20 and 25

试过了 可行 呵呵

select datepart(yyyy,getdate()) -出生日期 as 年龄 from table
where (datepart(yyyy,getdate()) -出生日期)>=20 and (datepart(yyyy,getdate()) -出生日期)<=25

select 2008-"出生日期'
from table
where 2008-"出生日期'>=20 AND 2008-"出生日期'<=25