假设我有以下数据:
Product
IdPk | Name
-------------
guid1 | Printer
guid2 | Oil
guid3 | Etc.
guid4 | Etc..
ProductPart
PartIdPk| ItemId | PartName
-------------------------
guid100 | guid1 | Ink
guid101 | guid1 | Paper
guid102 | guid2 | Automobile Fuel
guid103 | guid2 | Cooking
ProductPartType
TypeIdPk| ItemId | PartId | TypeName
---------------------------------
guid200 | guid1 | guid100 | Cyan < Types of ink
guid201 | guid1 | guid100 | Magenta
guid202 | guid1 | guid100 | Black
guid203 | guid1 | guid100 | Yellow
guid204 | guid1 | guid101 | Photocopier < Types of paper
guid205 | guid1 | guid101 | Envelope
guid206 | guid1 | guid101 | Card
guid207 | guid2 | guid102 | Petrol < Types of automobile fuel
guid208 | guid2 | guid102 | Diesel
guid209 | guid2 | guid103 | Olive < Types of cooking oil
guid210 | guid2 | guid103 | Sunflower
因此,每个产品都有一个或多个零件,每个零件都有一种或多种类型。
我想选择一个产品、它的零件和它的类型。假设我可能有数千个条目,所以通常我想在选择的同时进行过滤。这三个表通常会导致笛卡尔产品查询,鉴于这种情况,我需要运行一个查询,该查询相当于“给我按(部件为 Ink 的类型名称)排序的前 2 个产品,然后(类型名称在部分是烹饪)”
有没有人有任何想法?提前谢谢了