sql server查询NodeId字段中距离某一时间最近的所有数据
2017-07-27 16:43
411 查看
没别的啥,就是想写个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
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
相关文章推荐
- 有一个数据表,但是我只知道一个字段的名称。现在我想查询数据库里面的除去这个字段的所有数据!
- php连接sql server查询text字段丢失数据解决方法
- Oracle 查询库中所有表名、字段名、字段名说明,查询表的数据条数、表名、中文表名、
- 查询表里某个字段10-30之间的数据且ID不是连续的
- mysql查询某字段出现次数大于n的所有数据信息,还有对列出前三位
- 查询时将数据表中以;分隔的用户ID字段转换成以;分隔的用户名(原创)(备忘)
- MongoDB小技巧-用ObjectID查询某一时间范围内的数据
- mssql查询表中不重复数据的所有字段
- Android 查询Sqlite表中的数据时,表中必须得有_id字段,否则报错
- SQL Server查询一张表的所有字段
- php+sql server根据自增序号id区间查询第几条到第几条的数据
- 查询一个表中所有id字段在另一个表中对应值的SQL语句怎么写?
- Android 查询Sqlite表中的数据时,表中必须得有_id字段,否则报错
- sql server 查询所有表的字段的详细信息的存储过程(在 SQL Server 2005 中查询表结构及索引 )
- solr删除指定id文档,删除查询到是所有索引数据,删除所有数据
- SQL Server中查询某个字段中长度最短的一列数据
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名
- node.js+mongoose通过mongodb的id来查询数据id类型不对问题的解决
- sql语句查询Oracle|sql server|access 数据库里的所有表名,字段名