有一个数据表
A   B    C
---------------
a  12   100
a  22   90
a  7    100
b  66   98
b  2    98
c  23   96
c  66   99
现在想通过SQL语句,可以找出C条目最大的两个人(字段A),即 a和c 
不知道如何过滤掉重复A字段的条目,寻找实现这个功能的SQL语句=============================================================
此外,欢迎推荐比较经典的SQL语句的资料或者图书,thanks

解决方案 »

  1.   

    select a
    from (
    select a,max(c) as num
    from tb
    group by a
    )T
    order by num desc
    limit 2
      

  2.   

    参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    select a.* from tt a where not exists(select 1 from tt where a.a=a and a.c<c) limit 2
      

  4.   

    select a.* from tt a where not exists(select 1 from tt where a.a=a and a.c<c) limit 2
      

  5.   

    问题已经解决,谢谢各位,分数稍后送上。顺便想请教一下,关于SQL语句方面有没有比较好的书籍或者资料推荐推荐
    手头上的SQL资料都是最基本的语句介绍之类的东西。推荐书籍、资料也有分送上的。
      

  6.   

    《数据库系统概论(第四版)》 王珊 萨师煊   高等教育出版社 (掌握基础知识和概念) 然后再粗略浏览一遍MYSQL的官方手册。(方便以后查找,避免类似于考试的时候,给你本政治书也不知道答案在第几章,第几页)MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  7.   

    select (select * from table order by A,C) group by A
      

  8.   


    再补充一下 是 select * from (select * from table order by A,C desc) as r group by A你试试,绝对行