Return Mysql result as ranking

Asked

Viewed 63 times

0

As I should do in this query, where I have a user register, and each user sends several photos to another table, each photo sent receives a score of 1 to 5

I need to bring the 10 with the highest number of points and their respective points

The scoring field is named after picture_photo

SELECT * FROM t_login JOIN t_fotos ON id_login = id_login_foto LIMIT 0,10

2 answers

1


This can give a light, also think about using subSelects

SELECT *, MAX(punctua_photo) FROM t_login JOIN t_fotos ON id_login = id_login_foto GROUP BY id_login_foto ORDER BY Count(score_photo) DESC LIMIT 0.10

  • I think this doesn’t solve, I think he needs you to sort by the total sum of points that each user has with the photos.

  • Exactly @Brunohenrique

  • @Giba, yes, with a little adaptation, it worked perfectly, thank you

0

SELECT t_login.id_login, SUM(t_fotos.pontuacao_foto) 
FROM t_login JOIN t_fotos ON id_login = id_login_foto 
ORDER BY 2, 1 DESC LIMIT 0,10;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.