2012-08-04 219 views
1

如何僅選擇大於40天的日期?選擇日期和時間範圍

SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy 
    FROM Patient, Occupancy 
    WHERE EndOfOccupancy > 40 StartOfOccupancy; 

我想顯示該人已經在工作了40多天,他們結束了他們的入住前的數據,我已經試過無數的一些變體,但無法弄清楚如何構建線下決賽,並保持得到這個錯誤:

ORA-00932: inconsistent datatypes: expected DATE got NUMBER 

感謝您的任何幫助。

回答

0

嘗試

SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy 
FROM Patient, Occupancy 
WHERE EndOfOccupancy > DATE_ADD(StartOfOccupancy, INTERVAL 40 DAY) 
2

你將要檢查的邊界情況,看看你得到你想要的東西。如果您使用Oracle DATE數據類型,您可能希望比較TRUNC(EndOfOccupancy)和TRUNC(StartOfOccupancy)以擺脫時間組件。

SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy 
    FROM Patient, Occupancy 
    WHERE TRUNC(EndOfOccupancy) - TRUNC(StartOfOccupancy) >= 40;