1

以下查询选择输入“完成”的所有工作单元(第 7 行的子查询)。这很好用......当只有一个输入时。我该如何更改它,以便它要求每个输入都在子查询返回的集合中,而不仅仅是要存在的输入之一?

SELECT workunits.ID 
FROM workunits 
LEFT JOIN workunitInputs ON workunits.ID = workunitInputs.workunitID 
WHERE workunits.ID NOT IN (SELECT workunitID FROM jobworkunitassoc) 
AND ( 
    workunitInputs.inputID IN ( 
        SELECT workunitOutputs.outputID 
        FROM workunitOutputs 
        LEFT JOIN workunits ON workunitOutputs.workunitID = workunits.ID 
        LEFT JOIN jobworkunitassoc ON workunits.ID = jobworkunitassoc.workunitID 
        LEFT JOIN jobs ON jobworkunitassoc.jobID = jobs.ID 
        WHERE jobs.done = 1 
    ) 
    OR workunitInputs.inputID IS NULL 
) 
GROUP BY workunits.ID

谢谢,伊斯特万。

4

2 回答 2

0

将该条款更改为:

AND ( 
    workunitInputs.inputID NOT IN ( 
        SELECT workunitOutputs.outputID 
        FROM workunitOutputs 
        LEFT JOIN workunits ON workunitOutputs.workunitID = workunits.ID 
        LEFT JOIN jobworkunitassoc ON workunits.ID = jobworkunitassoc.workunitID 
        LEFT JOIN jobs ON jobworkunitassoc.jobID = jobs.ID 
        WHERE jobs.done != 1 
    )

这是基于逻辑重言式:Y 中的所有 X === !Y 中没有 X

于 2012-08-14T21:47:53.393 回答
0

这个查询对我有用,虽然它可能不是最好的解决方案:http: //pastebin.com/g9qBjQGU

于 2012-08-14T22:13:35.917 回答