1st Query:
------------------------------------------------------
SELECT T1.[ID],
T1.[SOT],
T1.[QtyPass],
T1.[QtyFail]
FROM Inspection AS T1
WHERE T1.[QtyPass] > 0 AND T1.[QtyFail] > 0
AND T1.[ID] = (SELECT MIN(T2.[ID])
FROM Inspection AS T2
WHERE T1.[SOT] = T2.[SOT]
AND T2.[QtyPass] > 0 AND T2.[QtyFail] > 0);
2nd Query:
-----------------------------------------------------------------------
SELECT T1.[ID],
T1.[SOT],
T1.[QtyPass],
T1.[QtyFail]
FROM Inspection AS T1
WHERE T1.[QtyFail] <> 0
AND T1.[SOT] IN (SELECT T2.[SOT]
FROM Inspection AS T2
WHERE T2.[QtyFail] <> 0
GROUP BY T2.[SOT]
HAVING SUM(IIF(T2.[QtyPass]=0,0,1)) = 0);
3rd Query:
-----------------------------------------------------------------------
SELECT T1.[ID],
T1.[SOT],
T1.[QtyPass],
T1.[QtyFail]
FROM Inspection AS T1
WHERE T1.[QtyPass] <> 0
AND T1.[SOT] IN (SELECT T2.[SOT]
FROM Inspection AS T2
WHERE T2.[QtyPass] <> 0
GROUP BY T2.[SOT]
HAVING SUM(IIF(T2.[QtyFail]=0,0,1)) = 0);
|