这个查询给了我错误,所以这个查询有什么问题?
SELECT recipes.recipeId as recipeId,
recipes.title as title,
recipes.cookingtime as cookingtime,
recipes.serving as serving,
schedule.catId as catId,
images.imagePath AS imagePath
FROM recipes
INNER JOIN schedule ON recipes.recipeId = schedule.recipeId
INNER JOIN images ON images.recipeId = recipes.recipeId
GROUP BY recipeId
WHERE schedule.day = 'saturday'
ORDER BY catId ASC
我认为查询中group by的位置不正确。
答案 0 :(得分:1)
应该是那样的,然后分组,然后命令
WHERE schedule.day = 'saturday'
GROUP BY recipeId
ORDER BY catId ASC
答案 1 :(得分:1)
你的想法是正确的。 GROUP BY
应该在WHERE
子句之后和ORDER BY
子句之前。
SELECT recipes.recipeId as recipeId,
recipes.title as title,
recipes.cookingtime as cookingtime,
recipes.serving as serving,
schedule.catId as catId,
images.imagePath AS imagePath
FROM recipes
INNER JOIN schedule ON recipes.recipeId = schedule.recipeId
INNER JOIN images ON images.recipeId = recipes.recipeId
WHERE schedule.day = 'saturday'
GROUP BY recipeId
ORDER BY catId ASC
答案 2 :(得分:1)
此处没有聚合功能,您无法使用group by
。
group by
条件在where
子句之后和order by
子句之前。
SELECT recipes.recipeId as recipeId,
recipes.title as title,
recipes.cookingtime as cookingtime,
recipes.serving as serving,
schedule.catId as catId,
images.imagePath AS imagePath
FROM
recipes INNER JOIN schedule
ON recipes.recipeId = schedule.recipeId
INNER JOIN images
ON images.recipeId = recipes.recipeId
-- GROUP BY recipeId
WHERE schedule.day = 'saturday' ORDER BY catId ASC
答案 3 :(得分:0)
只需替换
的顺序GROUP BY recipeId
之后
WHERE schedule.day = 'saturday'
它需要......
SELECT recipes.recipeId as recipeId,
recipes.title as title,
recipes.cookingtime as cookingtime,
recipes.serving as serving,
schedule.catId as catId,
images.imagePath AS imagePath
FROM recipes
INNER JOIN schedule ON recipes.recipeId = schedule.recipeId
INNER JOIN images ON images.recipeId = recipes.recipeId
WHERE schedule.day = 'saturday'
GROUP BY recipeId
ORDER BY catId ASC