写个SQL
表AA
结构如下:
   name      dt            age
   A        2001/01/02      65
   A        2002/01/02      45
   A        2003/01/02      44
   B        2001/01/02       2
   B        2002/01/02       5
要求找出  
   A        2003/01/02       44
   B        2002/01/02       5
(日期最大的所有记录)

解决方案 »

  1.   

    select top 2 * from AA order by desc
      

  2.   

    select top 2 * from AA order by dt desc
      

  3.   

    create table t_user(a varchar(10) , b varchar(10) , c varchar(10))
    insert into t_user (a,b,c)
    select 'A','2001-01-02','65'
    union 
    select 'A','2002-01-02','45'
    union 
    select 'A','2003-01-02','44'
    union 
    select 'B','2001-01-02','2'
    union 
    select 'B','2002-01-02','5'select t.* from t_user t
    where 2>(select count(*) from t_user where a=t.a and b>=t.b) 
    drop table t_user
      

  4.   

    select name,max(dt) from tab group by name
      

  5.   

    select * from aa a
    where not exists (
    select 1 from aa
    where name=a.name
    and dt>a.dt
    )
      

  6.   


    create table t_user(a varchar(10) , b varchar(10) , c varchar(10))
    insert into t_user (a,b,c)
    select 'A','2001-01-02','65'
    union
    select 'A','2002-01-02','45'
    union
    select 'A','2003-01-02','44'
    union
    select 'B','2001-01-02','2'
    union
    select 'B','2002-01-02','5'select t.* from t_user t
    where t.b=(select max(b) from t_user where a=t.a)