表的记录是这样的,
id  userid  score 
1   10        10
2   12        5
3   11        10
4   10        20
5   11        30userid 是有重复的,,我想求得userid  所有的score之和 中最高的上面 用户10  得分 30
     用户11       40
         12       5我最终得查找到用户11 ,40分,,sql语句怎么写啊

解决方案 »

  1.   

    SELECT userid,SUM(score) AS sumscore 
    FROM tablename 
    GROUP BY userid 
    ORDER BY sumscore DESC 
    LIMIT 1
      

  2.   

    SELECT userid,SUM(score) 
    FROM TT GROUP BY userid ORDER BY 2 DESC 
    LIMIT 1
      

  3.   

    select * from (
    select userid,sum(score) as s
    from 表的记录
    group by userid
    ) t
    order by s limit 1
      

  4.   

    select userid,sum(score) as s
        from 表的记录
        group by userid
    order by s limit 1
      

  5.   

    select userid,sum(score) as s
        from 表的记录
        group by userid
    order by s limit 1
      

  6.   

    SELECT userid,SUM(score) 
    FROM t GROUP BY userid ORDER BY 2 DESC 
    LIMIT 1;
      

  7.   

    SELECT userid,SUM(score) FROM t GROUP BY userid