最近有一个需求:APP端需要有一个热门的版块,热门的规则根据的是点赞数排序,分页不能有重复数据。
方案:
1、给表加多一个更新时间的字段,然后先按赞赏数逆序排序,再按更新时间顺序排序。
2、贴SQL;
<select id="querySharesByPage" parameterType=" " resultType=" ">
SELECT
*
FROM
shares
WHERE
1 = 1
AND FK_MOBILE IS NOT NULL
AND MIX_STATUE = 1
AND SH_STATUE = 1
<if test="updateTime != null and updateTime !='' "> <!-- updateTime != null and updateTime !='' -->
<![CDATA[
AND (
(
UPDATE_TIME > #{updateTime}
AND ZANS_COUNT = #{zansCount}
)
OR (ZANS_COUNT < #{zansCount})
)
]]>
</if>
ORDER BY
ZANS_COUNT DESC,
UPDATE_TIME ASC
limit #{rows}
</select>