search

Home  >  Q&A  >  body text

php - MySql的sql语句涉及group/sum/limit/结果集多字段,如何写

表结构和数据如下,我需要查询uid的total之和最大的前10条数据,请问sql语句如何写

uid   total
1      4
2      1
2      2
3      6
1      5
4      9
PHP中文网PHP中文网2816 days ago373

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-10 14:39:24

    SELECT uid, SUM( total ) 
    FROM  `test` 
    GROUP BY uid
    ORDER BY SUM( total ) DESC 
    LIMIT 0 , 10
    

    reply
    0
  • Cancelreply