假设我有一个表格,其中包含某些类型的记录,例如烹饪说明"Fold the melted chocolate into the egg whites".该表包含唯一的ID字段和字符串.
我想为配方构建另一个表(每个表都有唯一的ID和名称),每个表都是一系列顺序指令(一些指令将用于几个/多个配方).
构造配方表以将配方的唯一ID映射到连续的一系列指令(哪些ID不是连续的)的最佳方法是什么?
尝试这样的标准化设计:
recipe
id name
1 Recipe1
2 Recipe2
recipe_instruction
recipe_id instruction_id sortorder
1 5 1
1 3 2
1 4 3
2 6 1
2 7 2
2 3 3
Run Code Online (Sandbox Code Playgroud)
要获取特定配方的说明列表,您可以使用此查询:
SELECT i.the_string
FROM recipe_instruction AS ri
JOIN instruction AS i
ON ri.instruction_id = i.id
WHERE ri.recipe_id = 1
ORDER BY ri.sortorder
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
187 次 |
| 最近记录: |