您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



取出特定记录的前后 二条数据?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


取出特定记录的前后 二条数据?[已结贴,结贴人:lsxad]
发表于:2007-03-23 22:30:56 楼主
在一个记录集里如何取出   符合某个条件的前后二条数据。
如   数据库中有   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   取出后一条记录。
但这样做的话,记录多的时候速度很慢

请问各位   有没有更好的方法。


发表于:2007-03-23 23:52:231楼 得分:50
分两次
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   "
第一条
发表于:2007-03-24 01:18:012楼 得分:0
找到12后重新选两次
发表于:2007-03-24 19:23:273楼 得分:0
re:cqq_chen(我是谁)
你那样做的话   记录集大的话会很慢。
我现在想了二种方法,不知哪种效率高,记录有十几万条。
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
发表于:2007-03-26 11:59:224楼 得分:0
方法2快


快速检索

最新资讯
热门点击