问题
I have this query:
SELECT Field1, OrderFor, Writeback, Actshipdate, Orderstatus, receivedate, receivetime
FROM orderinfo, shippinginfo
WHERE orderinfo.orderid = shippinginfo.orderid
AND shippinginfo.custid = '37782'
AND receivedate = DATE(NOW())
AND receivetime = ???????
I am using Sybase adaptive server anywhere and trying to get records for the last hour.
回答1:
try this !!
SELECT Field1, OrderFor, Writeback, Actshipdate, Orderstatus, receivedate, receivetime
FROM orderinfo, shippinginfo
WHERE orderinfo.orderid = shippinginfo.orderid
AND shippinginfo.custid = '37782'
AND receivedate = DATE(NOW())
AND receivetime > DATEADD(HOUR, -1, GETDATE())
回答2:
Try below query:
SELECT Field1, OrderFor, Writeback, Actshipdate, Orderstatus, receivedate, receivetime
FROM orderinfo, shippinginfo
WHERE orderinfo.orderid = shippinginfo.orderid
AND shippinginfo.custid = '37782'
AND receivedate = DATE(NOW())
AND receivetime >= (sysdate-1/24);
回答3:
Similar to TeamDataViz's answer. Just a little more readable IMO.
SELECT Field1, OrderFor, Writeback, Actshipdate, Orderstatus, receivedate, receivetime
FROM orderinfo, shippinginfo
WHERE orderinfo.orderid = shippinginfo.orderid
AND shippinginfo.custid = '37782'
WHERE receivedate BETWEEN DATEADD(HOUR,-1,GETDATE()) AND CAST(GETDATE() AS DATE)
The WHERE Clause becomes even easier if you only wish to focus on records by Past DAY
WHERE receivedate > GETDATE() - 12
来源:https://stackoverflow.com/questions/19743850/get-records-from-last-hour