在一个记录集里如何取出 符合某个条件的前后二条数据。
如 数据库中有 11,12,13,14,22,23,24,25
首先有个条件:"< 20"
这样就出来了 11,12,13,14的记录集,然后需要取出 12 的前后二条数据。
我现在做法是
1,先 rst.open "select * from t_table where f_xh <20",cnn,3,2
2,然后是 rst.find f_xh = 12
3, rst.movefrist 取出前一条记录
4, rst.movenext
5, rst.movenext 取出后一条记录。
但这样做的话,记录多的时候速度很慢请问各位 有没有更好的方法。
如 数据库中有 11,12,13,14,22,23,24,25
首先有个条件:"< 20"
这样就出来了 11,12,13,14的记录集,然后需要取出 12 的前后二条数据。
我现在做法是
1,先 rst.open "select * from t_table where f_xh <20",cnn,3,2
2,然后是 rst.find f_xh = 12
3, rst.movefrist 取出前一条记录
4, rst.movenext
5, rst.movenext 取出后一条记录。
但这样做的话,记录多的时候速度很慢请问各位 有没有更好的方法。
rst.open "select * from t_table where f_xh <12 Order by DESC"
第一条
rst.open "select * from t_table where f_xh >12 Order by "
第一条
你那样做的话 记录集大的话会很慢。
我现在想了二种方法,不知哪种效率高,记录有十几万条。
1`,
select max(f_xh) from t_table where f_xh <12
select min(f_xh) from t_table where f_xh >12 2,
select top 1 * from t_table where f_xh <12 Order by DESC
select top 1 * from t_table where f_xh >12