需要帮助组合SQL查询

时间:2022-03-21 01:52:00

I need to some help regarding below query

我需要一些关于以下查询的帮助

select * from customers where orderdate < 01-09-2010 

select * from order where purchasedate < 01-09-2010

I want to combine above querys into one.

我想将上面的查询合并为一个。

As a result I want to get customers who have not placed order after 01-09-2010.

因此,我希望获得在2010年10月1日之后没有订购的客户。

2 个解决方案

#1


0  

need join key in two table. for example customer's name, query will be like this.

需要在两个表中加入密钥。例如客户的名字,查询将是这样的。

select a.*, b.*
from customers a, order b
where a.name = b.customer_name
and a.orderdate < 01-09-2010
and b.purchasedate > 01-09-2010

#2


0  

select c.*
from customers c 
left join order o on c.name = o.customer_name and o.purchasedate > 01-09-2010
where c.orderdate < 01-09-2010

#1


0  

need join key in two table. for example customer's name, query will be like this.

需要在两个表中加入密钥。例如客户的名字,查询将是这样的。

select a.*, b.*
from customers a, order b
where a.name = b.customer_name
and a.orderdate < 01-09-2010
and b.purchasedate > 01-09-2010

#2


0  

select c.*
from customers c 
left join order o on c.name = o.customer_name and o.purchasedate > 01-09-2010
where c.orderdate < 01-09-2010