Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL:Top-bewertete Artikel in jeder Kategorie finden

Probieren Sie diese aus

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

ODER

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