通过设置行数丝毫变量,然后过滤结果以显示仅第1-3行应该起作用
SET @last_objectId = 0;SET @count_objectId = 0;SELECt id, name, image FROM (SELECt user.id, user.name, user.image, @count_objectId := IF(@last_objectId = rating.objectId, @count_objectId, 0) + 1 AS rating_row_number, @last_objectId := rating.objectIdFROM usersLEFT JOIN ratings ON (ratings.userid = user.id)WHERe rating.rating > 0 AND rating.objectId IN (1,2,3,4)ORDER BY rating.objectId) AS subquery WHERe rating_row_number <= 3;



