我想在sql中创建表,其中行和列将是一些值,并且在(i,j)单元格中将存在相应的值。这样的事情:
----------------------------------------
| receipt/ingr | apple | banana | cream
----------------------------------------
| cake | 0 | 1 | 1
| salad | 1 | 1 | 0
----------------------------------------
因此1意味着配方含有成分。问题是,我有大量的成分和食谱,这样我就不能在select中手动写出名字了。我不知道如何创建这种格式。
我的表格:
Receipts (id, name)
Ingredients (id, name)
Receipt_ingredient (id, receipt_id, ingredient_id)
我该怎么办?提前致谢