Mysql多表分页查询

多张表,字段完全相同,表名称不同,每三个月的数据插入到一张表中。当查询历史的时候,把所有表中的数据展示出来并做分页处理。

sql语句的写法:

    <select  id = "queryAllDataByLimit"  parameterType = "hashmap" resultMap = "BaseResultMap">

             select * from ${fristName}

             where 1 = 1

             <if  test="state != null and state != ' '  ">

                      and state = #{state,jdbcType = INTEGER}

             </if>

             <if test="number != null and number !=' ' ">

                      and (sjrdh like concat ('%',#{number,jdbcType=VARCHAR},'%')

                      or hgh = #{number,jdbcType=VARCHAR})

             </if>

             <if test="tableNameList != null and tableNameList != ' ' ">                 

                         <foreach collection="tableNameList"  item="item" index ="index" >

                                   union

                                   select * from ${item}

                                   where 1 = 1

                                   <if  test="state != null and state != ' '  ">

                                                and state = #{state,jdbcType = INTEGER}

                                  </if>

                                 <if test="number != null and number !=' ' ">

                                                and (sjrdh like concat ('%',#{number,jdbcType=VARCHAR},'%') or

                                                hgh = #{number,jdbcType=VARCHAR})

                                 </if>

                         </foreach>

              </if>

             <if test="beginIndex != null and beginIndex != -1 ">

                          limit

                          #{beginIndex,jdbcType=INTEGER},#{pageSize,jdbcType=INTEGER}

              </if>

      </select> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值