SQL产品组合

时间:2011-05-17 18:00:52

标签: sql

我有一个如下所示的SQL数据库:enter image description here

使用此数据库...

如果我有产品,比如棉质衬衫,这个产品有三种选择,比如尺码,颜色和长袖或短袖。

我的CMS说我的产品有以下几种:
大 - 白色 - 长袖
大 - 绿色 - 长袖
大 - 绿色 - 短袖
小 - 白色 - 长袖

所以在我的网站的前端(在Javascript中)我可以说当选中Large时,启用White&绿色复选框。但是当选中Small时,我只需启用白色复选框等。

理想的结果如下:
依赖['大'] = [白,绿]
依赖['大,白'] = [长袖]
依赖['大,绿'] = [长袖,短袖]
依赖['小'] = [白]
依赖['小,白'] = [长袖]

SQL看起来可能是什么样的?

非常感谢任何帮助 谢谢

1 个答案:

答案 0 :(得分:1)

每次选择一个选项时,您都可以使用Javascript修改可用的选项,而不是进行查询。因此,您的初始查询只返回数组,XML或JSON中产品的所有数据,然后您可以根据需要在客户端过滤它。

select * --replace the * with the fields you actually want
from Product p
left outer join Option o on p.Id = o.ProductId
left outer join OptionValue ov on o.id = ov.OptionId
left outer join CombinationDetail cd on ov.Id = cd.OptionValueId
left outer join Combination c on cd.CombinationId = c.Id