Sql 如何在n个时间间隔后获取数据
我在sql server中每隔1秒存储一次数据,我需要每隔1或2分钟获取一次数据,而不是每秒获取一次数据,如何使用sql每隔2分钟获取一次数据Sql 如何在n个时间间隔后获取数据,sql,sql-server,datetime,Sql,Sql Server,Datetime,我在sql server中每隔1秒存储一次数据,我需要每隔1或2分钟获取一次数据,而不是每秒获取一次数据,如何使用sql每隔2分钟获取一次数据 select * from ( select *, datepart(minute, yourDate) mn, row_number() over(partition by datepart(minute, yourDate) order by yourDate) rn from yourTable )
select *
from
(
select *,
datepart(minute, yourDate) mn,
row_number() over(partition by datepart(minute, yourDate) order by yourDate) rn
from yourTable
) x
where (mn % 2) = 0
and rn = 1
我会这样处理:
select t.*
from (select t.*,
row_number() over (partition convert(date, datecol), datepart(hour, datecol), datepart(minute, datecol) / 2
order by datecol
) as seqnum
from t
) t
where seqnum = 1;
按划分的
将数据分成两分钟一组(由/2
完成)。然后,逻辑返回每个组中的第一条记录。日期列有大量重复项。为什么没有秒组件?我添加了表格格式。。