我想查询一分组记录的全部记录;
比如:select max(score) from students group by name;
这只能查出max(score)的值,但我想查询此记录的其他字段的值,请问该如何做?

解决方案 »

  1.   

    select s.* from students s where not exists(select 1 from students where name=s.name and score>s.score)select s.* from students s,(select name,max(score) as score from students group by name) v where s.name=b.name and s.score=v.score
      

  2.   

    select * /* 多了一个列rk,去掉就列出详细列名 */ from 
      (select  rank() over (partition by name order by score ) as rk,t.* from students t)
     where  rk=1;
      

  3.   

    修正
    select * /* 多了一个列rk,去掉就列出详细列名 */ from 
      (select  rank() over (partition by name order by score desc) as rk,t.* from students t)
     where  rk=1;
      

  4.   

    select * from students
    where (name,score) in
      (select name,max(score)
      from students
      group by name)
      

  5.   

    select * from students
    where (name,score) in
      (select name,max(score)
      from students
      group by name)
      

  6.   

    select a.* from students a,
    (select name,max(score) score from students group by name) b
    where a.name=b.name and a.score=b.score;
      

  7.   

    select a.* from students a,
    (select name,max(score) score from students group by name) b
    where a.name=b.name and a.score=b.score;select * from students 
    where (name,score) in (select name,max(score) from students group by name);