日期:2014-05-18 浏览次数:20390 次
日期 >= '2007-4-13 12:10:00 ' 的还 接近这个日期的50条数据 你这个接近是什么意思? 取大于'2007-4-13 12:10:00 '的最小的50个? select top 50 * from (select *,datediff(minute,'2007-4-13 12:10:00',SAMPLING_DATETIME) m from EFIXDATA WHERE (SITE_ID = '4001') AND (SAMPLING_DATETIME >= '2007-4-13 12:10:00')) t order by m
------解决方案--------------------
还是不是很明白
--这是查找'2007-4-13 12:10:00 '前后各50条记录的
select top 50 * from EFIXDATA
WHERE (SITE_ID = '4001 ') AND (SAMPLING_DATETIME < '2007-4-13 12:10:00 ')
ORDER BY SAMPLING_DATETIME desc
union
select top 50 * from EFIXDATA
WHERE (SITE_ID = '4001 ') AND (SAMPLING_DATETIME >= '2007-4-13 12:10:00 ')
ORDER BY SAMPLING_DATETIME
--这是查找>='2007-4-13 12:10:00 '不足50条的时候 再加上 <'2007-4-13 12:10:00 '的50条记录
select top 50 * from(
select top 50 * from EFIXDATA
WHERE (SITE_ID = '4001 ') AND (SAMPLING_DATETIME < '2007-4-13 12:10:00 ')
ORDER BY SAMPLING_DATETIME desc
union
select top 50 * from EFIXDATA
WHERE (SITE_ID = '4001 ') AND (SAMPLING_DATETIME >= '2007-4-13 12:10:00 ')
ORDER BY SAMPLING_DATETIME) tbl
order by tbl.SAMPLING_DATETIME