我正在尝试运行查询来选择客户受众,但它应该选择以前没有收到电子邮件的客户。电子邮件跟踪来自另一个表。这是原始查询:
SELECT
c.customers_firstname,
c.customers_lastname,
o.orders_id,
o.customers_id,
c.customers_email_address
FROM
orders o,
customers c,
order_status s
WHERE
o.customers_id = c.customers_id
AND o.orders_id = s.orders_id
AND o.orders_status = s.orders_status_id
ORDER BY
o.orders_id ASC
现在,我需要检查另一个名为 tracking 的表,看看该表中是否已经存在客户,如果存在,则跳过它。
这是我尝试过的,但它似乎不起作用:
SELECT
c.customers_firstname,
c.customers_lastname,
o.orders_id,
o.customers_id,
c.customers_email_address
FROM
orders o,
customers c
INNER JOIN
tracking t
ON
c.customers_id = t.customers_id,
order_status s
WHERE
o.customers_id = c.customers_id
AND o.orders_id = s.orders_id
AND o.orders_status = s.orders_status_id
AND c.customers_id NOT LIKE t.customers_id
ORDER BY
o.orders_id ASC
我究竟做错了什么?或者有什么办法可以更好地做到这一点?
补充:我完全忘记了一个更重要的因素 - 跟踪表有“模块”列,我只需要“联系”模块的结果。因此,换句话说,我需要过滤掉跟踪表中已经存在的客户,但前提是与联系人模块相关联,而不是与任何其他模块相关联。