select firstname+'.'+lastname as name,
age = DATEDIFF(yy,birthdate,GETDATE())
from employees
where convert(int,age) > 30
order by age desc说是没有列 age

解决方案 »

  1.   

    select firstname+'.'+lastname as name,
    age = DATEDIFF(yy,birthdate,GETDATE())
    from employees
    where convert(int,(DATEDIFF(yy,birthdate,GETDATE()))) > 30
    order by age desc
      

  2.   

    --這樣寫百分之百對
    select firstname+'.'+lastname as name,
    age = DATEDIFF(yy,birthdate,GETDATE())
    from employees
    where convert(int,(DATEDIFF(yy,birthdate,GETDATE()))) > 30
    order by DATEDIFF(yy,birthdate,GETDATE()) desc
      

  3.   

    select * from 
    (
    select firstname+'.'+lastname as name,
    age = DATEDIFF(yy,birthdate,GETDATE())
    from employees
    ) t
    where convert(int,t.age) > 30
    order by t.age desc
      

  4.   

    select firstname+'.'+lastname as name,
    age = DATEDIFF(yy,birthdate,GETDATE())
    from employees
    where convert(int,DATEDIFF(yy,birthdate,GETDATE())) > 30
    order by age desc