Oracle - 检查日期范围内是否有数据

时间:2016-05-23 06:22:16

标签: oracle

我有三张桌子(收据,收据,商店)。我有选择,这给了我一个数据,其中包含自宣布日期以来所有商店的所有收据:

select *
from receipts r
join receipt receiptaddinfo ri on r.receiptid=ri.receiptid and r.shop=ri.shop
join shops s on ri.shop=s.shop and shoptype=0
where ri.creationtime >= '2016-05-19 00:00:00' 
order by ri.creationtime desc

桌子商店,包含所有商店,但是,我想检查是否有商店,没有'销售/收据'自申报日期起。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试以下SQL语句。

SELECT * from shops s 
WHERE s.shoptype = 0 
AND NOT EXISTS 
(SELECT 1 
 FROM  receipts r,
       receiptaddinfo ri
 WHERE r.receiptid = ri.receiptid 
 AND   r.shop = ri.shop
 AND   ri.shop = s.shop 
 AND   ri.creationtime >= '2016-05-19 00:00:00')