select *
from tb a
where not exists(select* from tb where convert(char(7),导入日期,120)=convert(char(7),a.导入日期,120)
                                         and 导入日期>a.导入日期)

解决方案 »

  1.   

    select top 1 *
    from ta
    where 导入日期   between '2008-01-01 00:00:00' and '2008-04-31 23:59:59'
      

  2.   

    select top 1 * 
    from ta 
    where 导入日期   between '2008-01-01 00:00:00' and '2008-04-31 23:59:59'
    order by 导入日期 desc
      

  3.   

    回Haiwer
    导入日期精确到秒,一般不会重复的
      

  4.   

    回happyflystone :
       上一年最后一天的数据怎么输出??
      

  5.   

    最后一天的时间。
    declare @date datetime
    set @date = '2008-04-21'
    select cast(datepart(yy,@date) as nvarchar(20))+cast ('-12-31' as nvarchar(20))
      

  6.   

    select top 1 *  
    from ta  
    where 导入日期  < '2008-01-01'
    order by 导入日期 desc
      

  7.   

    回happyflystone 
      top 1 *  之后,我怎么只能取一条数据呀,我每天导一次,名称可能一样,金额和导入日期是不同的
       我有好几条数据都不一样,只能取一条
      

  8.   

    回laowan688 :用你的方法取的是当前年份的最后一天
      

  9.   


    回laowan688 : 
    知道了
    declare @date datetime 
    set @date = '2008-04-21' 
    select cast(datepart(yy,@date)-1 as nvarchar(20))+cast ('-12-31' as nvarchar(20))