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> 

猜你喜欢

转载自blog.csdn.net/little_soybean/article/details/78703483