表   table1
字段 time
字段  idtime字段id为54 有三个时间(2011-1-15 21:10:59)(2011-1-18 0:20:18)(2011-1-30 0:20:18)查询table1中的字段time,条件id=54,相隔的最大天数
以下代码得出三个时间,我要最大的天数,帮我改一下select datediff(day,time,getdate()) from table1 where id='54'

解决方案 »

  1.   


    select top 1 datediff(day,time,getdate()) from table1 where id='54' order by datediff(day,time,getdate()) desc
      

  2.   

    加入  将得到的值as aaa 怎么写
      

  3.   

    select top 1 datediff(day,time,getdate())  as aaafrom table1 where id='54' order by datediff(day,time,getdate()) desc
      

  4.   

    select top 1 datediff(day,time,getdate()) as aaafrom table1 where id='54' order by datediff(day,time,getdate()) desc
      

  5.   

    select top 1 datediff(day,time,getdate()) 
     from table1 where id='54' order by 1 desc
      

  6.   


    select top 1 datediff(day,time,getdate())  as aaa
     from table1 where id='54' order by 1 desc
      

  7.   

    select DATEDIFF(day, min([TIME]),max([TIME])) From [TABLE1] where ID=1
      

  8.   

    select DATEDIFF(day, min([TIME]),max([TIME])) From [TABLE1] where ID=54
      

  9.   


    select DATEDIFF(day, min([TIME]),getdate()) From [TABLE1] where ID=54
      

  10.   

    变通啊@!
    select DATEDIFF(day, min([TIME]),getdate()) From [TABLE1] where ID=54
      

  11.   

     相差天数,所以必须加个绝对值 abs()select top 1 abs(datediff(day,time,getdate())) as aaafrom table1 where id='54' order by abs(datediff(day,time,getdate())) desc
      

  12.   


    同志,你说 -17 和 +1 不加绝对值 top 选出来的是不是 + 1
    但正确要的 结果应该是 -17 的那个,也就是相差 17 天