我是 sql 的小菜鸟,我需要一些帮助。我有 3-4 个表,我想创建一个 sqlite 命令来返回一些行。表格如下。
表:餐厅
| Name | menuID | REFERENCES [Menu]([menuID])|
表:菜单
| MenuID | Name |
表:成分
| IngredientID | Name |
表:Food_Incl_ingredient
| FoodIncIngredientID | FoodID REFERENCES [Food][FoodID] | IngredientID REFERENCES [Ingredient]([IngredientID])|
表:食物
| FoodID | Name | Type | MenuID REFERENCES [Menu][MenuID]|
如果他们没有我要说的成分,我想查询以返回餐厅名称、食物名称和食物类型。谢谢你。
餐桌餐厅:
| Name | MenuId |
Goodys 2
Koumbaris 1
表菜单:
| MenuID | Name |
1 koumbarisMenu
2 goodysMenu
餐桌食物:
| FoodID | Name | Type | MenuID |
29 Chef's Salad Starter 2
31 Mama's Salad Starter 2
30 Ceasar's Salad Starter 2
表 Food_Incl_ingredient:
| FoodInclIngredientID | FoodID | IngredientID |
1 29 1
6 31 1
8 30 1
餐桌成分:
| IngredientID | Name |
1 Cereals
2 Shellfish
SQL查询:
SELECT Restaurant.Name, Food.Name, Food.Type
FROM Restaurant
INNER JOIN Menu ON Restaurant.menuID = Menu.MenuID
INNER JOIN Food ON Menu.MenuID = Food.MenuID
INNER JOIN Food_Incl_ingredient ON Food.FoodID = Food_Incl_ingredient.FoodID
INNER JOIN Ingredient ON Food_Incl_ingredient.FoodInclIngredientID = Ingredient.IngredientID
WHERE Ingredient.Name == 'Cereals'
预期成绩:
| Name | Name | Type |
Goodys Chef's Salad Starter
Goodys Mama's Salad Starter
Goodys Ceasar's Salad Starter
我得到的唯一结果是第一行。