背景:文档管理系统中有两种不同的文档类型。Doc Type A 和 Doc Type B 都有一个 Ticket # 和一个 Ticket Date。我们正在寻找:Doc Type A 文档没有匹配的 Doc Type B 文档(不存在)且 Ticket # 和 Ticket Date 相同。类似的 Doc Type B 文档具有相同的 Ticket # 但不同的 Ticket Date。我们想忽略这些。看起来很简单......但我被卡住了。到目前为止,我所拥有的是这样的:
SELECT
DISTINCT ki110.keyvaluechar AS "Ticket #",
ki101.keyvaluedate AS "Ticket Date"
FROM
itemdata
LEFT OUTER JOIN
hsi.keyitem110 ki110 on ( itemdata.itemnum = ki110.itemnum )
LEFT OUTER JOIN
hsi.keyitem101 ki101 on ( itemdata.itemnum = ki101.itemnum )
WHERE
ki101.keyvaluedate BETWEEN '01-01-2021' AND '01-31-2021'
AND
(
itemdata.itemtypenum = 178
) -- this is Doc Type A
AND NOT EXISTS
(
SELECT
ki110.keyvaluechar,
ki101.keyvaluedate
FROM
itemdata,
keyitem110 ki110 ,
keyitem101 ki101
WHERE --(itemdata.itemnum = ki110.itemnum) --Ticket #
-- ** the problem is here for Date: I need to say Date in Doc Type B doc is not the same as Date in Doc Type A doc using ki101.keyvaluedate)
AND itemdata.itemtypenum = 183) -- this is DOC Type B