3个表 学生表 (学号 姓名 系名 年龄)成绩表(学号 课程号 成绩)课程表(课程号 课程名)求年龄在20到22之间的数学系学生的学号,姓名和出生年份学习中 求各位大大帮解下~~

解决方案 »

  1.   


    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.系名='数学系'
      

  2.   


    select a.学号,a.姓名,datepart(yy,datediff(yy,a.年龄,getdate()))
    from 学生表 a
    where a.年龄 between 20 and 22
      and a.系名 = '数学系'
      

  3.   


    --修改
    select a.学号,a.姓名,datepart(year,datediff(year,-a.年龄,getdate()))
    from 学生表 a
    where a.年龄 between 20 and 22
      and a.系名 = '数学系'