Mysql
 sql >> Database >  >> RDS >> Mysql

SQL:trova l'articolo più votato in ogni categoria

Prova questi

SELECT id, category_id, rating
FROM   articles a1
WHERE rating = 
(SELECT MAX(a2.rating) FROM articles a2 WHERE a1.category_id = a2.category_id)

O

SELECT * FROM (SELECT * FROM articles ORDER BY rating DESC) AS a1 GROUP BY a1.rating;