gpt4 book ai didi

mysql 查询不包含分层表的地方

转载 作者:行者123 更新时间:2023-11-29 09:10:25 24 4
gpt4 key购买 nike

所以基本上我将 3 个表连接在一起。主表是配方,然后是配料表,然后是配料。

所以我需要一个查询,其中只有不含鸡肉的食谱。我遇到的问题是,因为食谱有很多成分,当我使用 where != 时,它只是删除了肉中的成分,但留下了其他成分......我如何解释多种成分。

select Recipe.name as "No chicken"  from Recipe inner join IngredientList on Recipe.recipeId=IngredientList.recipeId inner join Ingredients on IngredientList.IngredientId=Ingredients.ingredientId where type!="chcicken" group by Recipe.name;

最佳答案

您的原始语句有一个没有聚合函数的GROUP BY。这没有道理。如果您尝试排序,它应该是 ORDER BY

尝试这样的事情:

SELECT `Recipe`.`name` AS "No chicken"
FROM `Recipe`
WHERE `Recipe`.`RecipeId` NOT IN (
SELECT DISTINCT `IngredientList`.`RecipeId` AS `RecipeID`
FROM `IngredientList`
INNER JOIN `Ingredients` ON `IngredientList`.`IngredientId` = `Ingredients`.`IngredientId`
WHERE `Ingredients`.`Type` = 'chicken'
)
ORDER BY `Recipe`.`name`

根据您的架构,如果您获得重复的配方名称,您可能需要在主选择语句中使用SELECT DISTINCT

关于mysql 查询不包含分层表的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5768796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com