sql_上移_下移_置顶_置底


    <!--置顶-->
    <update id="moveTop" parameterType="com.hisign.oses.entity.os.Jcybxx">
        UPDATE
        <include refid="TableClause"/>
        SET XH = (CASE WHEN XH = #{xh} THEN 1 ELSE XH + 1 END)
        WHERE
        instr(
        (SELECT if(rn = 1, NULL, bhs) FROM (
        SELECT group_concat(BH) AS bhs, count(*) AS rn FROM (
        SELECT BH FROM
        <include refid="TableClause"/>
        WHERE
        WTZJBH = #{wtzjbh} AND XH <![CDATA[  <= ]]> #{xh} AND SCBJ = 0) t) t), BH) <![CDATA[  > ]]> 0
    </update>

    <!--上移-->
    <update id="moveUp" parameterType="com.hisign.oses.entity.os.Jcybxx">
        UPDATE
        <include refid="TableClause"/>
        SET XH = (CASE WHEN XH = #{xh} THEN #{xh} - 1 ELSE #{xh} END)
        WHERE
        instr(
        (SELECT if(rn = 2, bhs, NULL) FROM (
        SELECT group_concat(BH) AS bhs, count(*) AS rn FROM (
        SELECT BH FROM
        <include refid="TableClause"/>
        WHERE
        WTZJBH = #{wtzjbh} AND XH <![CDATA[  <= ]]> #{xh} AND SCBJ = 0 ORDER BY XH DESC LIMIT 2 ) t) t), BH) <![CDATA[  > ]]> 0
    </update>

    <!--下移-->
    <update id="moveDown" parameterType="com.hisign.oses.entity.os.Jcybxx">
        UPDATE
        <include refid="TableClause"/>
        SET XH = (CASE WHEN XH = #{xh} THEN #{xh} + 1 ELSE #{xh} END)
        WHERE
	    instr(
        (SELECT if(rn = 2, bhs, NULL) FROM (
		SELECT group_concat(BH) AS bhs, count(*) AS rn FROM (
		SELECT BH FROM
        <include refid="TableClause"/>
		WHERE
        WTZJBH = #{wtzjbh} AND XH <![CDATA[  >= ]]> #{xh} AND SCBJ = 0 ORDER BY XH LIMIT 2 ) t) t), BH) <![CDATA[  > ]]> 0
    </update>

    <!--置底-->
    <update id="moveBottom" parameterType="com.hisign.oses.entity.os.Jcybxx">
        UPDATE
        <include refid="TableClause"/>
        SET XH = (CASE WHEN XH = #{xh} THEN @maxord ELSE XH - 1 END)
        WHERE
        instr(
        (SELECT if(rn = 1, NULL, bhs) FROM (
        SELECT group_concat(BH) as bhs, count(*) AS rn, (SELECT @maxord:= (SELECT MAX(XH))) AS maxord FROM
        (SELECT BH,XH FROM
        <include refid="TableClause"/>
        WHERE WTZJBH = #{wtzjbh} AND XH <![CDATA[  >= ]]> #{xh} AND SCBJ = 0) t) t),BH) <![CDATA[  > ]]> 0
    </update>
上一篇:AtCoder Beginner Contest 221 A~E题解


下一篇:STC15系列单片机学习之LED点灯