S
S
Sergey2018-11-02 22:08:29
SQL Server
Sergey, 2018-11-02 22:08:29

How to remake the SQL query so that it returns data for the last 5 minutes from the current time?

Query to MSSQL

SELECT TOP 1 TimeVal,Remark FROM pLogData WHERE Remark LIKE "%Тревога%" ORDER BY TimeVal DESC

gives out 2018-10-05 13:44:21.000 Тревога дверь 1
how you can redo the request so that it gives out only data for the last 5 minutes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-11-02
@Raschen

Obviously subtract 5 minutes from the current date and compare the result with the date of the entries

SELECT TimeVal,Remark FROM pLogData 
WHERE Remark LIKE "%Тревога%" AND TimeVal >= DATEADD(minute,-5,GETDATE()) ORDER BY TimeVal DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question