获取SUM(val)相同AS MAX(SUM(val))的记录

时间:2015-01-21 15:15:42

标签: mysql group-by sum max

我的SQL:

SELECT prefs.* 
FROM form_answer fa 
JOIN game g ON g.id = fa.game_id
JOIN customer c ON c.code = fa.`data`
JOIN (
    SELECT c.code code, p.pnt_version_id ver, prod_type, ROUND(SUM(value)/40*100,1) AS val
    FROM point p JOIN customer c
    GROUP BY c.code, p.pnt_version_id, prod_type
    ORDER BY val DESC   
) prefs ON g.pnt_version_id = prefs.ver AND c.code = prefs.code

WHERE fa.game_id = 44 AND fa.question_id = 34
ORDER BY prefs.val DESC

+------+-----+-----------+------+
| code | ver | prod_type | val  |
+------+-----+-----------+------+
|  101 | 110 |         1 | 87.5 |
|  101 | 110 |         3 | 87.5 |
|  101 | 110 |         2 | 62.5 |
+------+-----+-----------+------+

现在我只需要获得具有相同val AS MAX(val)的记录。有什么帮助吗?

0 个答案:

没有答案