在sql查询中显示早于当前日期的日期

时间:2013-08-08 02:05:42

标签: sql oracle date

在我的sql语句中,我有一个SQL语句,我需要显示哪些客户的返回日期已过期,即早于当前日期,到目前为止我的查询如下所示:

SELECT customers.firstname, items.itemname, CustEquipment.ReturnDate, customers.phonenumber
FROM items join
 CustEquipment
 on items.ItemId = CustEquipment.ItemId join
 customers 
 on CustEquipment.customerID=customers.customerID

目前显示所有客户及其返回日期(以及我需要的其他信息),但我想显示已经超过当前日期的退货日期,有人愿意指出我正确的方向吗?

2 个答案:

答案 0 :(得分:4)

您可以在where子句中进行日期比较:

SELECT customers.firstname, items.itemname, CustEquipment.ReturnDate, customers.phonenumber
FROM items join
     CustEquipment
     on items.ItemId = CustEquipment.ItemId join
     customers 
     on CustEquipment.customerID=customers.customerID
where ReturnDate <= trunc(sysdate);

我还调整了您的查询以使用正确的join语法。

答案 1 :(得分:0)

select C.Firstname,I.ItemName,CE.ReturnDate,C.PhoneNumber
from Items I
inner join CustEquipments CE
on 
CE.ItemID=I.ItemID
inner join Customers C
on 
C.CustomerID=CE.CustomerID
where 
convert(varchar(10),getdate(),101)>convert(varchar(10),CE.ReturnDate,101)