Paging duplication of data

Some time ago, the test to a bug, the front end of the first display and second pages of data duplication, but also the background debug test. The sql console to print a test run about visualization tools, the problem is still there.

Then remove the page and found that there is no problem. There is a problem in that page. Later consult our company chiefs. He said it might be because you have duplicate field values ​​that situation, plus the best that can guarantee the uniqueness of the field to sort the data.

Before did not change the sql

select * from(
        select
        <include refid="Base_Column_List"/>,
        case
        when TRAIN_STATUS=1
        then '1'
        when TRAIN_STATUS=2
        then '2'
        when TRAIN_STATUS=3
        then '3'
        when TRAIN_STATUS=5
        then '5'
        when (to_char(TRAIN_START_DATE, 'yyyy-mm-dd') || TRAIN_START_TIME) >
        to_char(sysdate, 'yyyy-mm-ddHH24:mi')
        then '4-1'
        when (to_char(TRAIN_END_DATE, 'yyyy-mm-dd') || TRAIN_END_TIME) >
        to_char(sysdate, 'yyyy-mm-ddHH24:mi')
        then '4-2'
        else '4-3'
        end as STATUS
        from TB_TRAINING_INFO
        order by
        case
        when STATUS='1'
        then 1
        when STATUS='3'
        then 2
        when STATUS='4-1'
        then 3
        when STATUS='4-2'
        then 4
        when STATUS='4-3'
        then 5
        when STATUS='2'
        then 6
        else 7
        end asc
        )
        <where>
            <if test="trainName!=null and trainName!=''">
                and TRAIN_NAME like '%' || #{trainName,jdbcType=OTHER} ||'%'
            </if>
            <if test="originatorName!=null and originatorName!=''">
                and ORIGINATOR_NAME like '%' || #{originatorName,jdbcType=OTHER} || '%'
            </if>
            <if test="originatorOrgName!=null and originatorOrgName!=''">
                and ORIGINATOR_ORG_NAME like '%' || #{originatorOrgName,jdbcType=OTHER} || '%'
            </if>
            <if test="trainStatus!= andNull  trainStatus!=''">
                and TRAIN_STATUS = #{trainStatus,jdbcType=CHAR}
            </if>
            <if test="originator!=null and originator!=''">
                and ORIGINATOR = #{originator,jdbcType=OTHER}
            </if>
            <if test="status!=null and status!=''">
                and STATUS = #{status,jdbcType=OTHER}
            </if>
            and delete_flag='0'
        </where>

His status to get value from the sql above is repeated, and then I add a field to solve the problem. Attach modify sql

select * from(
        select
        <include refid="Base_Column_List"/>,
        case
        when TRAIN_STATUS=1
        then '1'
        when TRAIN_STATUS=2
        then '2'
        when TRAIN_STATUS=3
        then '3'
        when TRAIN_STATUS=5
        then '5'
        when (to_char(TRAIN_START_DATE, 'yyyy-mm-dd') || TRAIN_START_TIME) >
        to_char(sysdate, 'yyyy-mm-ddHH24:mi')
        then '4-1'
        when (to_char(TRAIN_END_DATE, 'yyyy-mm-dd') || TRAIN_END_TIME) >
        to_char(sysdate, 'yyyy-mm-ddHH24:mi')
        then '4-2'
        else '4-3'
        end as STATUS
        from TB_TRAINING_INFO
        order by
        case
        when STATUS='1'
        then 1
        when STATUS='3'
        then 2
        when STATUS='4-1'
        then 3
        when STATUS='4-2'
        then 4
        when STATUS='4-3'
        then 5
        when STATUS='2'
        then 6
        else 7
        end asc,UPDATE_DATE desc
        )
        <where>
            <if test="trainName!=null and trainName!=''">
                and TRAIN_NAME like '%' || #{trainName,jdbcType=OTHER} ||'%'
            </if>
            <if test="originatorName!=null and originatorName!=''">
                and ORIGINATOR_NAME like '%' || #{originatorName,jdbcType=OTHER} || '%'
            </if>
            <if test="originatorOrgName!=null and originatorOrgName!=''">
                and ORIGINATOR_ORG_NAME like '%' || #{originatorOrgName,jdbcType=OTHER} || '%'
            </if>
            <if test="trainStatus!=null and trainStatus!=''">
                and TRAIN_STATUS = #{trainStatus,jdbcType=CHAR}
            </if>
            <if test="originator!=null and originator!=''">
                and ORIGINATOR = #{originator,jdbcType=OTHER}
            </if>
            <if test="status!=null and status!=''">
                and STATUS = #{status,jdbcType=OTHER}
            </if>
            and delete_flag='0'
        </where>

Summary: order by the time the last goal on the basis of the sort field should be added that can guarantee the uniqueness of the field to sort the data

Guess you like

Origin www.cnblogs.com/jiangweichao/p/11163515.html