0

我有一个废弃的购物车查询,以便创建一个邮寄列表。我不想做的一件事是向任何在放弃购物车日期后下订单的人发送电子邮件,我将如何将其添加到以下内容:

select *
from cart
where order_status = ''
and date_ordered = '0000-00-00'
and customer_email IS NOT NULL
and date_added > subdate(current_date, 1)
and date_added < current_date
and brand Is Not Null
and customer_email != ' '
group by customer
order by date_added desc;

所以现在我想排除在同一天的订单中存在客户 ID 的记录。以免在他们下订单后第二天给他们发电子邮件。

提前致谢。

4

1 回答 1

1

左连接包含电子邮件地址上的订单(假设此处再次购物车)和不同订单(假设 order_id 检查此部分)的表并检查 NULL

select a.*
from cart a
LEFT OUTER JOIN cart b
ON a.customer_email = b.customer_email AND a.order_id != b.order_id
where a.order_status = ''
and a.date_ordered = '0000-00-00'
and a.customer_email IS NOT NULL
and a.date_added > subdate(current_date, 1)
and a.date_added < current_date
and a.brand Is Not Null
and a.customer_email != ' '
AND b.customer_email IS NULL
group by a.customer
order by a.date_added desc;
于 2013-07-02T10:11:59.673 回答