小弟想做一个分页,需求是第一页显示数据库最后十条数据,第二页显示后20-后10
SQL应该怎么写
SELECT b.* FROM这是查询前十的怎样从后面开始取值 ,实现时间最晚的在最前面
(
SELECT ROW_NUMBER() OVER(ORDER BY c.log_id) rowIndex,* FROM [log] c
) b
WHERE b.rowIndex>10 AND b.rowindex<=20
------解决思路----------------------
<select id="selectPages" resultMap="BaseResultMap" parameterType="java.util.Map">
select
<include refid="Base_Column_List" />
from POST_API_LOGS
where 1=1
<if test="id != null">
and ID = #{id,jdbcType=BIGINT}
</if>
<if test="requestSource != null">
and REQUEST_SOURCE = #{requestSource,jdbcType=BIGINT}
</if>
<if test="apiName != null">
and API_NAME = #{apiName,jdbcType=BIGINT}
</if>
<if test="apiType != null">
and API_TYPE = #{apiType,jdbcType=BIGINT}
</if>
<if test="requestStatus != null">
and REQUEST_STATUS = #{requestStatus,jdbcType=BIGINT}
</if>
<if test="mdate != null">
and MDATE = #{mdate,jdbcType=BIGINT}
</if>
<if test="cdate != null">
and CDATE = #{cdate,jdbcType=BIGINT}
</if>
order by CDATE DESC
<if test="pageBegin != null">
<if test="pageSize != null">
LIMIT #{pageSize,jdbcType=BIGINT} OFFSET #{pageBegin,jdbcType=BIGINT}
</if>
</if>
</select>
这个是Mybatis下的一个例子,你把里面的东西该一下就好。 pageSize是 页面展示的条数,PageBegin是开始展示的页数。