Mysql多表分页查询

来源:互联网 发布:nba1516数据库· 编辑:程序博客网 时间:2024/06/05 00:58

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


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> 

原创粉丝点击