sqlserver 获取每组最接近某个时间点的一条数据

 

with 
T1 as (
    SELECT   ROW_NUMBER()
        over   
        (PARTITION By MachineCode order by ABS(DATEDIFF(MILLISECOND,'2019-12-10 13:21:32.162' ,[Time]))) as rowid,*
FROM EnergyConsumptions   
) 
select * from T1 where rowid=1

 

posted @ 2020-05-21 17:19  も不秃不秃  阅读(1006)  评论(0编辑  收藏  举报