数据库中有出生年月,利用它用SQL语句写出到龄退休人的列表(男60岁,女55岁)、并且是让退休时间提前三个月的表

解决方案 »

  1.   


    select * FROM TABLENAME WHERE 
    (SEX='男' and  datediff(Month,birthday,getdate())=723 )
    or
    (SEX='女' and  datediff(Month,birthday,getdate())=663)
      

  2.   

    try
    select * from @t 
    where dateadd(year,60,date) between dateadd(month,-3,getdate()) and getdate()
    and SEX='男' or 
    (dateadd(year,55,date) between dateadd(month,-3,getdate()) and getdate()
    and SEX='女')
      

  3.   


    try
    select * from 表
    where dateadd(year,60,出生日期) between dateadd(month,-3,getdate()) and getdate()
    and 性别='男' or 
    (dateadd(year,55,出生日期) between dateadd(month,-3,getdate()) and getdate()
    and 性别='女')