如何仅选择超过40天的日期?
SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy
FROM Patient, Occupancy
WHERE EndOfOccupancy > 40 StartOfOccupancy;
我想要显示这个人在他们结束入住之前已经工作超过40天的数据,我已经尝试了很多变量,但是无法弄清楚如何构建最后一行并继续得到这个错误:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
感谢您的帮助。
答案 0 :(得分:2)
您需要检查边界情况,看看您是否得到了您想要的东西。如果您使用的是Oracle DATE数据类型,您可能希望比较TRUNC(EndOfOccupancy)和TRUNC(StartOfOccupancy)来摆脱时间组件。
SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy
FROM Patient, Occupancy
WHERE TRUNC(EndOfOccupancy) - TRUNC(StartOfOccupancy) >= 40;
答案 1 :(得分:0)
试
SELECT name, gender, WardNo, StartOfOccupancy, EndOfOccupancy
FROM Patient, Occupancy
WHERE EndOfOccupancy > DATE_ADD(StartOfOccupancy, INTERVAL 40 DAY)