select * from table1 where datediff("d",add_date,getdate())=0

解决方案 »

  1.   

    select col1,col2,..,max(add_date) as date from table1
    group by col1,col2,..
      

  2.   

    select add_date=max(add_date) as date from table1
      

  3.   

    select *,date=max(add_date) from table1
      

  4.   

    select * from table where add_date=
    select top 1 add_date from table group by add_date order by add_date
      

  5.   

    select * 
    from table1 
    where datediff("d",add_date
                    ,isnull((select max(add_date) from table1),getdate()))=0
      

  6.   

    select *,max(add_date) as maxdate from table1
    group by 字段名字
      

  7.   

    select * from table1 a where add_date=(
    select max(add_date) from table1)
      

  8.   

    select id,max(add_date) as date from table1
    group by id
      

  9.   

    如果你的add_date已经格式化到日期(就象你举例的)select * from table1 a where add_date=(
    select max(add_date) from table1)如果没有格式化到日期:select * from table1 a where datediff(day,add_date,(
    select max(add_date) from table1))=0
      

  10.   

    谢谢大家的帮忙
    查最后一天的日期是可以,但现在有一个问题就是在table1表中userid字段必须要跟session("username")相同,sql语句如下:
    select * from table1 where userid='"&session("username")&"' and add_date=(select max(add_date) from table1)
    这样就造成了userid相同而最新日期就不能匹配了,我必须要userid和add_date同时匹配,如何修改呀
      

  11.   

    求出來是可以,但要提取与userid相匹配的add_date字段,现在的问题是求的总个add_date的最大日期,请高手指点!!!