表A 
组名称   组成员   日期
 A        ABC 2004-1-1
 A        ABE 2005-2-1
 C        CBD 2004-1-2
 C        CBF 2004-1-3
 F        FDE 2007-1-1
想要结果
组名称    组成员   日期
 A        ABE 2005-2-1
 C        CBF 2004-1-3
 F        FDE 2007-1-1
一条SQL完成!!!
谢谢!

解决方案 »

  1.   

    select * 
    from 表 a where 日期>all
             (select max(日期) from 表 where 组名称=a.组名称)
      

  2.   

    select * from 表A t1,
    (select 组名称,max(组成员) from 表A group by 组名称)t2
    where t1.组名称= t2.组名称 and t1.组成员 = t2.组成员
      

  3.   

    select * from 表A where not exists(select 1 from 表A where 组名称=a.组名称 and 组成员=a.组成员 and 日期>a.日期)
      

  4.   

    --是: >all
    select * 
    from 表 a where 日期>any
             (select max(日期) from 表 where 组名称=a.组名称)
      

  5.   

    coolingpipe(冷箫轻笛) :谢谢你
    只不过我的组成员没有顺序规律的,所以不能把它转换为聚合列显示出来
      

  6.   

    --测试下:
    declare @t table(组名称 varchar(20),组成员 varchar(10),日期 varchar(10))
    insert into @t select  'A','ABC','2004-1-1'
    union all select 'A','ABC','2005-2-1'
    union all select 'C','CBD','2004-1-2'
    union all select 'C','CBD','2004-1-3'
    union all select 'F','FDE','2007-1-1'select * from @t where 日期>=any
    (select max(日期) from @t group by 组名称)--结果
    /*
    组名称                  组成员        日期
    -------------------- ---------- ----------
    A                    ABC        2005-2-1
    C                    CBD        2004-1-3
    F                    FDE        2007-1-1(3 行受影响)*/
      

  7.   

    select gname ,max(guser) ,max(date)
    from @t
    group by gname
      

  8.   


    create table S1 (组名称 char,组成员 varchar(10),日期 datetime)
    insert into S1
    select 'A','ABC','2004-1-1'
    union all
    select 'A','ABE','2005-2-1'
    union all
    select 'C','CBD','2004-1-2'
    union all
    select 'C','CBF','2004-1-3'
    union all
    select 'F','FDE','2007-1-1'
    select * from s1
    select * from s1 A
    where not exists(select * from S1 B where A.组名称=B.组名称 and A.日期>B.日期)
    才是真正的正解