本文介绍了过去1年没有订单的客户以及未下订单的客户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去1年没有订单的客户以及未下订单的客户





客户tbl:customerid,名称,电子邮件

订单tbl:customerid,orderdate,ordernumber

customers who dont have orders in last 1 year and also customers who does not placed orders


customer tbl : customerid, name ,email
orders tbl: customerid , orderdate , ordernumber

推荐答案

select distinct c.customerid,c.name,c.email,o.ordernumber
from Orders o
right join Customers c on o.customerid=c.customerid
where DATEDIFF(DAY,o.orderdate,GETDATE())>365 or o.orderdate IS Null


SELECT customerid, name from customer c, order o
where c.customerid = o.customerid
and c.customerid not in (select distinct customerid from order where orderdate between getdate() and getdate() - 365)







希望这能为您提供所需的输出。





干杯




Hope this will give you required output.


Cheers


这篇关于过去1年没有订单的客户以及未下订单的客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:46