25

我有这个查询:

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 = ???????

我在任何地方都在使用 Sybase 自适应服务器,并试图获取最后一小时的记录。

4

3 回答 3

40

尝试这个 !!

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())
于 2013-11-02T16:54:18.473 回答
2

试试下面的查询:

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);
于 2013-11-02T16:25:16.627 回答
0

类似于 TeamDataViz 的回答。只是更具可读性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)

如果您只想关注过去 DAY 的记录,WHERE 子句会变得更加容易

WHERE receivedate > GETDATE() - 12
于 2019-02-12T16:45:26.137 回答