一个表里有很多个人的成绩 然后我想把每个人的最好成绩都选出来 

解决方案 »

  1.   

    select *
    from 成绩表 t
    where not exists(select * from tb where 姓名=t.姓名 and 成绩>t.成绩)如果成绩表里没有姓名就用学号
      

  2.   

    http://blog.chinaunix.net/u/29134/showart_411484.html
      

  3.   

    如果你的表的成绩表是放在一个字段里的 
    像这样表aaa  id(自增长主键) uid(用户id) chengji(成绩) kemu(科目)
    类似这样的表结构的话那么使用max即可实现你的功能
    比如:
    select max(chengji) from aaa where uid = 666如果你的表结构像这样
    表bbb  uid(用户id) chengji1(科目一成绩)  chengji2(科目2成绩)  chengji3(科目3成绩)
    我暂时还不知道怎么写,另外我认为这样的表结构是不合理的
      

  4.   

    select max(chengji) from tblname  group by userid
      

  5.   

    补充一下我刚才发的帖子第二个方案的解决方法,我找到了答案,哈哈
    求某几列中最大值   
      select   greatest(col1,col2,col3...)   from   tablename;   
      求某几列中最小值   
      select   least(col1,col2,col3...)   from   tablename;