I have this MySQL query for list a "Vote Ranking" for "Actions" and it work fine, but I want what the "id_user" doesn't repeat, like made a "DISTINCT" in this field.
SELECT
count(v.id) votos,
v.id_action,
a.id_user,
a.id_user_to,
a.action,
a.descripcion
FROM
votes v,
actions a
WHERE
v.id_action = a.id
GROUP BY
v.id_action
ORDER BY
votos DESC
The result:
votes act 开发者_如何学Cid_user
3 3 745059251
2 20 1245069513
2 23 1245069513
2 26 100000882722297
2 29 1245069513
2 44 1040560484
2 49 1257441644
2 50 1040560484
The expected result
votes act id_user
3 3 745059251
2 20 1245069513
2 26 100000882722297
2 44 1040560484
2 49 1257441644
2 50 1040560484
If you don't want duplicate users, you should group by a.id_user
only. Then you will have to aggregate your actions, so you may want a sum(a.action)
or count(a.action)
in place of a.action. It's hard to tell what you should use without knowing what an 'action' represents.
精彩评论