对不起,如果我没有正确地问这个问题。我需要编写一个针对日志的查询。在日志中有一个列注释,用于跟踪过程中每个步骤的成功。我需要的是一份工作单" fjobno"有一个WCutSuccess ...在一个日期范围内的注释字段和相同的工作订单" fjobno"有ASSYSuccess ...在另一个日期范围我要列出它。我似乎无法弄明白。我确定它很简单。我确信人们会一直这样做。如果有人能指出我正确的方向,我会很感激。
select
inm.fgroup, inm.fpartno, jod.fjobno, sqb.note
from
inmast as inm
left join
jodbom as jod on inm.fpartno = jod.fbompart
left join
sqbclog as sqb on jod.fjobno = sqb.job
where
(inm.fgroup = 'isl' or inm.fgroup = 'iss')
and
(sqb.note = 'WCutSuccess...'
and sqb.stamp between '09/01/2014' and '10/01/2014')
and
(sqb.note = 'ASSYSuccess...'
and sqb.stamp between '10/01/2014' and '10/09/2014')
答案 0 :(得分:1)
我稍微更改了您的查询,因此它使用IN
代替col = something or col = somethingelse
。
我也改变了你选择日期范围的方式。
SELECT inm.fgroup,
inm.fpartno,
jod.fjobno,
sqb.note
FROM inmast AS inm
LEFT JOIN jodbom AS jod
ON inm.fpartno = jod.fbompart
LEFT JOIN sqbclog AS sqb
ON jod.fjobno = sqb.job
WHERE inm.fgroup IN ('isl','iss')
AND (
( sqb.note = 'WCutSuccess...'
AND sqb.stamp >= '20140109'
AND sqb.stamp < '20140111')
OR( sqb.note = 'ASSYSuccess...'
AND sqb.stamp >= '20140110'
AND sqb.stamp < '20140911')
)