简体   繁体   中英

How to SELECT timestamp for every 5 minutes from date in MS SQL Server?

I'm using MS SQL Server and I need SELECT that return only data like:

SELECT TOP 100000 [timestamp], [value] as fi500
FROM X
where timestamp>='2019-11-05' + 5 minute
order by timestamp

So I got:

我有:

But I need like:

在此处输入图像描述

Can somebody please help me?

It is possible to use MOD in WHERE clause.

If timestamp is stored as seconds it could be

... WHERE MOD(timestamp, 300) = 0...

to check if seconds number is divisible by 60*5.

Your code looks like SQL Server. You can check that the timestamp meets your conditions using datetimefromparts() and

select top (100000) [timestamp], [value] as fi500
from X
where timestamp = datetimefromparts(2019, 11, 05,
                                    datepart(hour, timestamp),
                                    (datepart(minute, timestamp) / 5) * 5,
                                    0, 0
                                   )
order by timestamp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM