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