2016-06-08 24 views
0

在MS Access 2010中,我有一個名爲MyTable的具有以下字段的表:MS訪問「在」使用正在採取永遠

visit_id, client_id, associate_id, startTime, StopTime, VisitDate 

我想找到不具有之間訂了參觀同夥Time1和Time2在某個日期。

我所選擇的方法是檢查其同夥不要在那些有間隔內訪問的查詢轉起來,如下列:

Select associate_id from 
myTable 
Where associate_id not in 
    (select associate_id from Mytable where visitStart <= Time2 AND VisitStop > Time1) 

這永遠需要在MS Access 2010中運行,並不是一個可行的解決方案。 MS Access中有更高效的解決方案嗎?

回答

2

您可以嘗試將DISTINCT關鍵字添加到子查詢中。

如果不幫助你可以嘗試這樣的事:

Select associate_id 
From myTable 
Group by associate_id 
Having sum(IIf(startTime <= Time2 AND StopTime> Time1, 1, 0) = 0 

你最好還是要篩選,當然VisitDate。

+0

非常感謝。使用「HAVING」解決了我的問題。 –