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

解决方案 »

  1.   

    既然以name分组了,那score只能以分组的来了,一个name对应一个score
    要不就
    select score from students group by name,score;
    以name+score共同分组.
      

  2.   

    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
      

  3.   

    select ...
        from (select t.*, row_number() over(patition by name order by score desc) rrr from t ...)
        where rrr=1;