MySQL使用LIMIT AND WHERE选择SUM

时间:2013-08-17 19:46:25

标签: mysql

我试图选择一些限制为2的值的SUM。我已经看过几个这样的例子(9877872)但是无法让它工作。我有

SELECT SUM(points) 
FROM 
(SELECT points FROM user_table 
WHERE city=1 AND group =5)  
AS min_points ORDER BY points DESC LIMIT 2

但是查询结尾处的limit子句似乎没有被执行,我只是得到了表中所有用户的总和......

有谁知道我做错了什么......?

1 个答案:

答案 0 :(得分:2)

试试这个

    SELECT SUM(points) 
FROM 
(SELECT points FROM user_table 
WHERE city=1 AND group =5 ORDER BY points DESC LIMIT 2)  AS t1