select count(*) from table
where datediff(year,col,getdate())>=30 and datediff(year,col,gedate())<=40
......`

解决方案 »

  1.   

    LeftEdge = 年龄段边界1 
    RightEdge = 年龄段边界2 select count(*) 
    from table
    where datediff(year,col,getdate())>=LeftEdge 
          and datediff(year,col,gedate())<=RightEdge 
      

  2.   

    CrazyFor(Fan):谢谢你的回复,这个方法我想到了,关键是要求精确的统计,比如有个人的生日是1972年12月4日,而今天是12月3日,他就是29岁,而不能算成30岁,虽然用datediff得出的结果也是30。难点就在这里,能否想想是否有别的好的方法?
      

  3.   

    精确到天:
    year(time1)-year(time2) + case when (month(time1)*100+day(time1))>=(month(time2)*100+day(time2)) then 0 else -1 end
      

  4.   

    ((year(time1)*10000+month(time1)*100+day(time1))-
    (year(time2)*10000+month(time2)*100+day(time2)))
    /10000
      

  5.   

    年龄段:
    ((year(time1)*10000+month(time1)*100+day(time1))-
    (year(time2)*10000+month(time2)*100+day(time2)))
    /2000
      

  6.   

    sky_blue(老衲) :我替你解释了  :)