我需要在数据库(mySQL)中以键值对的形式存储少量项目及其属性.我打算按照以下方式做到这一点.
我将使用两个表items和item_properties.
items
itemId | itemName ------------------- 1923 | AC 1235 | Fridge 8273 | Heater
item_properties
itemId | property | value -------------------------------- 1923 | effect | cooling 1923 | consumption | efficient 1923 | type | split 1235 | effect | cooling 1235 | volume | 20 liters 8273 | effect | heating 8273 | consumption | efficient 8273 | heatMethod | coil
现在,如果我必须选择"效果"为"冷却"的项目,我可以使用以下查询(这将在结果中给出'AC'和'Fridge').
SELECT itemName FROM items i, item_properties p WHERE i.itemId=p.itemId AND (p.property …