获取上一小时的记录

时间:2013-11-02 16:03:31

标签: sql sybase sybase-asa

我有这个问题:

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自适应服务器并尝试获取最后一小时的记录。

3 个答案:

答案 0 :(得分:22)

试试这个!!

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())

答案 1 :(得分:0)

尝试以下查询:

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);

答案 2 :(得分:-1)

类似于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)

如果您只希望在过去的一天之前关注记录,WHERE子句将变得更加简单

WHERE receivedate > GETDATE() - 12