select 学号,姓名,YEAR(dateADD(year,1-A.年龄,getdate())) AS 出生年份 from 学生表 a,成绩表 b,课程表 c where a.学号=b.学号 and b.课程号=c.课程号 and a.年龄 between 20 and 22 and a.系名='数学系'
select a.学号,a.姓名,datepart(yy,datediff(yy,a.年龄,getdate())) from 学生表 a where a.年龄 between 20 and 22 and a.系名 = '数学系'
--修改 select a.学号,a.姓名,datepart(year,datediff(year,-a.年龄,getdate())) from 学生表 a where a.年龄 between 20 and 22 and a.系名 = '数学系'
select 学号,姓名,YEAR(dateADD(year,1-A.年龄,getdate())) AS 出生年份 from 学生表 a,成绩表 b,课程表 c
where a.学号=b.学号
and b.课程号=c.课程号
and a.年龄 between 20 and 22
and a.系名='数学系'
select a.学号,a.姓名,datepart(yy,datediff(yy,a.年龄,getdate()))
from 学生表 a
where a.年龄 between 20 and 22
and a.系名 = '数学系'
--修改
select a.学号,a.姓名,datepart(year,datediff(year,-a.年龄,getdate()))
from 学生表 a
where a.年龄 between 20 and 22
and a.系名 = '数学系'