标准SQL分页
查询t_table表中所有记录第10到20条,按id排序。
SQL语句为:
又如查询t_table表中key='123'第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'
当然条件中的id可以换为任何能表识记录顺序的字段。