所以我有一个如下表:
| steamid | payment_amount |
199 5.00
501 10.00
199 15.00
238 5.00
238 1.00
所需的输出:
199 20.00
501 10.00
238 6.00
我试图选择按Steamid与Payment_amount的总和分组的数据,但是没有按预期出来?
例如:
SELECT steamid, sum(payment_amount) AS total FROM payments GROUP BY steamid
答案 0 :(得分:0)
SELECT steamid, SUM(payment_amount) AS total FROM payments GROUP BY steamid ORDER BY total DESC
通过按上述查询中的总desc顺序添加顺序,您可以在查询中进行较小的更改即可获得结果。
答案 1 :(得分:0)
添加ORDER BY total DESC
以按降序对结果进行排序
添加LIMIT 10
以选择前10名
结果声明:
SELECT steamid, sum(payment_amount) AS total FROM payments GROUP BY steamid ORDER BY total DESC LIMIT 10