Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get records from last hour

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.

like image 809
JeffreyLazo Avatar asked Nov 02 '13 16:11

JeffreyLazo


People also ask

How do I get last 1 hour data in SQL?

Here is the SQL to show latest time using now() function. Here is the SQL to get last 1 hour data in MySQL. In the above query, we select only those rows whose order_date falls within past 1 hour interval. We use INTERVAL clause to easily substract 1 hour interval from present time obtained using now() function.

How do I get last 2 hours data in SQL?

It seems that Time is a TEXT field. You should consider to combine Date and Time to get a DateTime field, and then use it in the WHERE clause. Show activity on this post. alter table report add datetimecol as (CAST(date as datetime) + time); create index idx_report_datetimecol on report(datetimecol);

How do I get the last 24 hours record in SQL?

You better make it "order_date >= DateAdd(DAY, -1, GETDATE())" thats it!


2 Answers

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())
like image 172
vhadalgi Avatar answered Oct 02 '22 15:10

vhadalgi


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);
like image 31
user3540800 Avatar answered Oct 02 '22 17:10

user3540800