赞
踩
我需要在数据库(mySQL)中以键值对的形式存储少量项目及其属性.我打算按照以下方式做到这一点.
我将使用两个表项和item_properties.
项目
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 = 'effect' AND p.value ='cooling');
我想知道如何编写查询来选择匹配多个属性的项目
>选择“效果”为“冷却”且“消费”为“高效”的所有项目(与项目“AC”匹配).
>选择“类型”为“拆分”的所有项目或“热量方式”为“线圈”或“消费”为“有效”(这将匹配项目“交流”和“加热器”).
请帮助…提前致谢!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。