日期:2014-05-16  浏览次数:20507 次

DB2分页语句的注意地方
今天其他业务组说我写的数据访问有些问题,调用我的分页接口时,会有相同的数据返回。
后来发现问题出在db2的分页语句上。

SELECT 字段列表 FROM (SELECT 字段列表, ROW_NUMBER() OVER() AS ROW FROM TABLE_NAME) AS TMP WHERE TMP.ROW BETWEEN 1 AND 10

这句:SELECT 字段列表, ROW_NUMBER() OVER() AS ROW FROM TABLE_NAME + ORDER BY ROW ASC

变成

SELECT 字段列表 FROM (SELECT 字段列表, ROW_NUMBER() OVER() AS ROW FROM TABLE_NAME ORDER BY ROW ASC) AS TMP WHERE TMP.ROW BETWEEN 1 AND 10