-------------------SQL Server 为例 ----取第1-2 数据进行计算-------------------
/*按照时间倒序,取第一条*/
select TOP (1) * from CP_youjia order by UpdateTime desc;
/*按照时间倒序,取前两条*/
select TOP (2) * from CP_youjia order by UpdateTime desc;
/*按照时间倒序,取前两条*/-/*前两条数据,按照时间顺序,取第一条*/=/*倒数第二条数据*/
select TOP (1) * from (select top (2) * from CP_youjia order by UpdateTime desc/*按照时间倒序,取前两条*/) a order by UpdateTime asc;/*前两条数据,按照时间顺序,取第一条*/
取最接近当前时间的2条记录进行计算
思路:
(1)/*按照时间倒序,取第一条*/
(2)/*按照时间倒序,取前两条*/
(3)/*前两条数据,按照时间顺序,取第一条*/
(4)/*按照时间倒序,取前两条*/-/*前两条数据,按照时间顺序,取第一条*/=/*倒数第二条数据*/