我正在执行此SQL查询:
SELECT * FROM tickets t
WHERE t.status <> 'Completed'
AND NOT EXISTS (SELECT u.ticketnumber
FROM ticket_updates u
WHERE u.type = 'update' AND u.ticketnumber = t.ticketnumber)
从ticket_updates表中没有行的2个表中选择两个表中的ticketnumber = ticketnumber
。
如何更改此查询以返回ticket_updates where customer <> 'Y'
答案 0 :(得分:0)
只需在子查询中添加另一个AND
条件
SELECT * FROM tickets t
WHERE t.status <> 'Completed'
AND NOT EXISTS (SELECT u.ticketnumber
FROM ticket_updates u
WHERE u.type = 'update' AND u.ticketnumber = t.ticketnumber
AND u.customer <> 'Y'
)
答案 1 :(得分:0)
SELECT t.*, tu.*
FROM tickets t
LEFT JOIN ticket_updates tu ON t.ticketnumber = tu.ticketnumber
WHERE tu.ticketnumber IS NULL AND t.status <> 'Completed' AND tu.customer <> 'Y'