我在MySQL中为一家Electron 商务网站提供了以下表格(Offer_Properties):
+----------+-------------+---------+
| offer_id | pkey | pvalue |
+----------+-------------+---------+
| 63 | shoesize | shoe_47 |
| 63 | sport | walking |
| 63 | color | multi |
| 12 | color | multi |
| 12 | shoesize | size_48 |
| 12 | shoesize | size_47 |
| 12 | shoesize | size_46 |
| 12 | sneakertype | comfort |
| 12 | sport | running |
+----------+-------------+---------+
找到优惠的最简单方法是什么?
shoesize = size_48 AND sport = running
我可以在
select offer_id from offer_properties where (pkey = "sport" and pvalue = "running") and offer_id IN (select offer_id from offer_properties where (pkey = "shoesize" and pvalue = "size_48"));
然而,这种递归方法真的很困难,因为可能会有各种属性匹配请求.此外,我还有其他表需要连接,查询很快就会变得很复杂.我有一个表保存值(价格、描述等),另一个规范化表保存优惠标签.
I LEFT JOIN
来查找将某些标签与某些属性和某些值相匹配的报价.然而,事情很快就变得非常复杂.
对于这种情况,你会有什么指导意见?我是否应该使用带有promise 的简单查询,并使用应用程序逻辑一步一步地过滤事物?
非常感谢