0

我有一个系统,可以将用户收到的产品积压在一个盒子里。整个系统基于我们创建的这些套件,其中包含产品。

所以我得到了一个CustomersProducts其中列出了我拥有的所有东西。我有一个Boxes表格,其中包含ProductID1, ProductID2, ProductID3 and ProductID4字段和CustomerID字段来指出哪个客户收到了哪个盒子。

我想做的就是,给定一组不同顺序的产品(例如:)ID4, ID2, ID3, ID1,我需要知道所有没有收到该组产品的客户。

我的数据库设计不好?执行此操作或如何进行SELECT查询的最佳方法是什么

4

1 回答 1

1

你可以做你想做的事:

where id4 not in (productid1, productid2, productid3, productid4) or
      id2 not in (productid1, productid2, productid3, productid4) or
      id3 not in (productid1, productid2, productid3, productid4) or
      id1 not in (productid1, productid2, productid3, productid4)

您应该有一个名为类似的表BoxesrProducts,其中包含 aBoxesId和 a ProductId。这样,如果需要,盒子可以有不同的尺寸——甚至超过 4 个产品。

于 2013-04-02T21:21:43.953 回答