2016-05-23 65 views
2

我有三張表(收據,receiptaddinfo,商店)。我有選擇,這給了我一個數據與自申報日起所有從所有的商店收據: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

你可以試試下面的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') 
+0

非常感謝,這給了我想要的東西。 – headder

相關問題