如果结构是这样的!
name   group  age  
a       v      13
b       v      14
c       v      13
d       w      14
e       w      12
........
返回结果是name    group    age
b        v        14
d        w         14
.......结果解释:简单的说就是我想返回同一个GROUP中AGE最大的那条记录,如果同时有多人的AGE都是最大的话,就从中随机选择一条返回

解决方案 »

  1.   

    select name, [group], sex=max(sex)
    from tb
    group by name, [group]
      

  2.   

    select name,group,max(age) as age from table group by name,group
      

  3.   

    -- 如果还有其他列, 则需要你的表中有一个主键(或者唯一键)来定位记录才行
    select * from tb a
    where not exists(
       select * from tb
       where name=a.name and [group]=a.[group]
             and 主键<a.主键)
      

  4.   

    create table A
    (
      name1 varchar(10),
      group1 varchar(10),
      age int
    )insert A select 'a','v',13
    insert A select 'b','v',14
    insert A select 'c','v',13
    insert A select 'd','w',14
    insert A select 'e','w',12
    select * from A T where name1=(select top 1 name1 from A where group1=T.group1 order by age DESC)