作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我面临的问题是,我想加入这两个查询。
SELECT recipes.RecipeID ,recipes.Name,recipes.ImageThumb,recipes.RatingTotal,
count(ratings.RecipeID) AS trates
FROM recipes
JOIN ratings
ON ratings.RecipeID = recipes.RecipeID
WHERE recipes.Name LIKE '%ade%'
ORDER BY Name;
这个查询没有按预期工作,当有多个结果时它会带来 1 个结果,并且比率是所有结果的总和,而不仅仅是那个特定的 RecipeID
最佳答案
我想这就是您要找的:
SELECT recipes.RecipeID ,recipes.Name,recipes.ImageThumb,recipes.RatingTotal,
COUNT(ratings.RecipeID) AS trates
FROM recipes
LEFT JOIN ratings
ON ratings.RecipeID = recipes.RecipeID
WHERE recipes.Name LIKE '%ade%'
GROUP BY RecipeID
ORDER BY Name;
关于Mysql,加入查询,一头雾水,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792733/
我是一名优秀的程序员,十分优秀!