0

在我的 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

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

4

2 回答 2

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语法。

于 2013-08-08T02:07:13.360 回答
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)
于 2013-08-08T07:23:55.763 回答