我有用作索引的树表:
link_flavor_and_iceCream具有列:flavor_ID,iceCream_ID
link_color_and_iceCream具有列:color_ID,iceCream_ID
link_fans_and_iceCream有列:fan_ID,iceCream_ID
每个iceCream可以有许多不同的口味,颜色和粉丝
我需要查询所有有香味的冰淇淋" vanila"或"巧克力"和颜色"粉红色"或"红色"或" brown"和" jack"或者"乔"作为粉丝...
我该怎么做?我怎么能把所有这些放在同一个视图上?
非常感谢!!
答案 0 :(得分:0)
鉴于我们不知道你的限制性标记的字段名称或者什么是iceCream表(或者即使你有一个)它看起来像什么......
像这样......SELECT IC.Name
FROM iceCream IC
INNER JOIN Link_flavor_and_IceCream ICF
IC.IceCream_ID = ICF.IceCream_ID
and favor in ('Vanila', 'Chocolate')
INNER JOIN Link_color_AndIceCream ICC
and ICC.IceCream_Id = IC.IceCream_ID
and color in ('Pink','Red','Brown')
INNER JOIN Link_Fans_and_IceCream ICFan
and IC.IceCream_ID = ICFan.IceCream_ID
and ICFan.Name in ('Jack','Joe')
或者...
SELECT IC.Name
FROM iceCream IC
INNER JOIN Link_flavor_and_IceCream ICF
IC.IceCream_ID = ICF.IceCream_ID
INNER JOIN Link_color_AndIceCream ICC
and ICC.IceCream_Id = IC.IceCream_ID
INNER JOIN Link_Fans_and_IceCream ICFan
and IC.IceCream_ID = ICFan.IceCream_ID
WHERE
IFC.favor in ('Vanila', 'Chocolate')
and ICC.color in ('Pink','Red','Brown')
and ICFan.Name in ('Jack','Joe')
或许多其他方式......包括使用或陈述而不是