sql server查詢NodeId字段中距離某一時間最近的所有數據

沒別的啥,就是想寫個sql語句

sql語句:

 select * from
    (select nodeId,max(UpdateTime)as UpdateTime
        from JT_InspectNode_Update
        where PathID in (1, 2)
        and deltag = 0
        and UpdateTime <=
            (select MAX(UpdateTime)as UpdateTime
                from JT_InspectNode_Update
                where UpdateTime <= '2017-07-24 11:51:30')
        group by nodeId) as t1,
        (select * from JT_InspectNode_Update where PathID in (1,2) and deltag = 0)as t2
        where t1.NodeId = t2.NodeId and t1.UpdateTime = t2.UpdateTime order by t2.NodeId


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章