mybatis配置and rownum< minus 查询第几行到第几行数据的sql原型和mybatis原型。

6 篇文章 0 订阅

mybatis配置and rownum<  minus 查询第几行到第几行数据的sql原型和mybatis原型:


sql原型如下:

select
    
   t.pk_id as wq
  
    FROM t1t
    
    where dr=0
    
      and rownum<10  minus 
      
    
    
    select
    
    t.pk_id as 12
  
    FROM t1t
      where dr=0
    
      and rownum>2   
      
      order by JGqwMC desc


mybatis的mapper配置文件原型如下:

<select id="exportCurrentPage" resultMap="CorrectEndExcelMap"
parameterType="java.util.Map">
<if test="searchText != null">
<bind name="searchTextLike" value="'%' + _parameter.searchText + '%'" />
</if>
<if test="xm != null">
<bind name="xmLike" value="'%' + _parameter.xm + '%'" />
</if>
select
    
    t.pk_id as JGMC
  
    FROM t1  t
    
    <where>
<trim prefixOverrides="and">
 t.DR=0  
 <![CDATA[
and rownum<10  minus 
]]>
</trim>
    
     </where>
    
    select
    
    t.pk_id as JGMC
  
    FROM t1 t
    
    <where>
<trim prefixOverrides="and">
t.DR=0   and rownum>2 
</trim>
    
    </where>
      
      order by JGMC desc

</select>


注意:如果需要配置自定义的排序,需要如下设置,因为oracle的rownumber是不会变化的(此处的排序规则是:order by t.pk_id):

select * from(
select ROW_NUMBER() over(order by t.pk_id) as rowIndex , rownum,t.PK_ID
 FROM t1t
WHERE t.DR=0  and t.VSTATUS>=1


 ) t
 where   rowIndex<= 40 
 and  rowIndex>=20


或者利用minus写了更为复杂的写法(不推荐)

select * from(
select ROW_NUMBER() over(order by t.pk_id) as rowIndex , rownum,t.PK_ID

FROM t1 t 
WHERE t.DR=0 and   t.VSTATUS>=1
 ) t
 where   rowIndex<= 40 
minus
select * from(
select  ROW_NUMBER() over(order by t.pk_id) as rowIndex , rownum, t.PK_ID

FROM t1 t 
WHERE t.DR=0 and t.VSTATUS>=1 
 
) t
 where   rowIndex < 20 +1
 
 ;


此处的排序规则是:order by t.pk_id



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值