考虑两个表交易和客户。 我想选择过去2个月没有完成交易的客户的记录。
交易包含
From_CustomerId
客户包含
CustomerId,电子邮件
From_CustomerId 是他们之间唯一的外键,我想选择
电子邮件
最近两个月的时间范围。谢谢!
答案 0 :(得分:1)
你可以这样做
select
c.* from Customer c
left join Transaction t on t.From_CustomerId = c.CustomerId
and t.date between curdate()-interval 2 month and curdate()
where t.From_CustomerId is null