我们能根据实际情况来选择适合自己的方法,我给大家介绍一个通过标准的sql语句来得到符合条件的数据。如从第10到20条的符合条件(where语句中的)的记录。通过这种方法取得记录有一个必要条件,必须有一个能够标识记录顺序的字段,如id,time等等。下面我为大家演示一个例子: 查询t_table表中所有记录第10到20条,按id排序。 sql语句为: select * from t_table t1 where (select count(*) from t_table t2 where t2.id < t1.id ) >= 10 and (select count(*) from t_table t2 where t2.id < t1.id ) < 20
又如查询t_table表中key=123第10到20条的记录,按id排序。 select * from t_table t1 where (select count(*) from t_table t2 where t2.id < t1.id and t2.key = 123) >= 10 and (select count(*) from t_table t2 where t2.id < t1.id and t2.key = 123) < 20 and t1.key = 123