我有一个像这样的表结构:
产品
PRODUCTS_STAGES
PRODUCTS_STAGES
PRODUCTS_STATUSES
PRODUCTS_STAGES_SET
PRODUCTS_STATUSES_SET
在PRODUCTS_STATUSES中有4种状态(Id-name):
PRODUCTS_STAGES有6个阶段。
我有这样的查询:
SELECT p.Id_products FROM PRODUCTS AS p
INNER JOIN (SELECT pss.Id_products FROM PRODUCTS_STAGES_SET AS pss
INNER JOIN PRODUCTS_STATUSES_SET AS pss2 ON pss.Id_products_stages_set = pss2.Id_products_stages_set
WHERE pss2.Id_products_statuses IN (1,2,3)
GROUP BY pss.Id_products) ps
ON p.Id_products = ps.Id_products
此查询为我提供的产品至少一个阶段不已完成
现在我想要一个查询,它给我的产品只有特定的阶段状态。例如,我希望产品具有 stage2 = Started
答案 0 :(得分:0)
SELECT p.Id_products FROM PRODUCTS AS p
INNER JOIN (SELECT pss.Id_products FROM PRODUCTS_STAGES_SET AS pss
INNER JOIN PRODUCTS_STATUSES_SET AS pss2 ON pss.Id_products_stages_set = pss2.Id_products_stages_set
WHERE pss2.Id_products_statuses = 2
GROUP BY pss.Id_products) ps
ON p.Id_products = ps.Id_products