0
SELECT     favourites.FavouriteID, 
           favourites.User, 
           favourites.RecipeID,
           recipes.RecipeID,
           recipes.Name,
           recipes.CategoryID,
           recipes.RatingTotal,
           recipes.ImageMed,    
           count(ratings.RecipeID) AS trates ,
           (recipes.RatingTotal / COUNT(ratings.RecipeID)) as avg
FROM       favourites
                  RIGHT JOIN recipes 
                         on recipes.RecipeID = favourites.RecipeID
                  LEFT JOIN ratings 
                         ON ratings.RecipeID = recipes.RecipeID
WHERE favourites.user = '$Cuser' 
GROUP BY ratings.RecipeID 
ORDER BY avg  DESC, trates DESC  
LIMIT  $offset,20

嗨,这个查询总共带来了 3 条记录,但它们是 7 条,还有其他 4 条没有通过,因为它们在评级表中没有记录,我该如何调整?

收藏夹表包含用户已添加到收藏夹列表的食谱的食谱 ID,我正在尝试在查询中显示收藏夹表中的食谱,该食谱由具有最高稀有度的人排序。但是没有评分的没有显示

4

1 回答 1

0

错误似乎在数据中。可能违反了收藏夹和食谱之间的关系完整性。显示您的测试数据。

于 2012-08-18T21:18:17.423 回答