过去1年没有订单的客户以及未下订单的客户 [英] customers who dont have orders in last 1 year and also customers , who does not placed orders

查看:98
本文介绍了过去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

推荐答案

试试这个..



Try this..

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


您好,



仅从您的上述信息我可以写下面的查询。试试这个...



Hi,

From your above info only i can write below query. Try this...

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年没有订单的客户以及未下订单的客户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆