1

如何仅选择大于 40 天的日期?

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

我想显示该人在结束入住之前已经工作超过 40 天的数据,我尝试了许多变体,但无法弄清楚如何构建最后一行并不断收到此错误:

ORA-00932: inconsistent datatypes: expected DATE got NUMBER

谢谢你的帮助。

4

2 回答 2

2

您将需要检查边界情况,看看您是否得到了您想要的。如果您使用 Oracle DATE 数据类型,您可能希望比较 TRUNC(EndOfOccupancy) 和 TRUNC(StartOfOccupancy) 以摆脱时间组件。

SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy  
  FROM Patient, Occupancy  
  WHERE TRUNC(EndOfOccupancy) - TRUNC(StartOfOccupancy) >= 40; 
于 2012-08-04T12:17:12.690 回答
0

尝试

SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy
FROM Patient, Occupancy
WHERE EndOfOccupancy > DATE_ADD(StartOfOccupancy, INTERVAL 40 DAY)
于 2012-08-04T12:05:58.787 回答