puzhibing
2024-03-06 1baad5a501915c41ebabd0b619cca6470af66bf9
cloud-server-communityWorldCup/src/main/resources/mapper/WorldCupCompetitorMapper.xml
@@ -94,4 +94,69 @@
        </if>
    </select>
    <select id="worldCupRecordsList" resultType="map">
        select @row_num := @row_num + 1 AS row_num, bb.* from (
            select * from (
                select
                a.participantType,
                a.participantId,
                a.appUserId,
                a.num as totalSession,
                ifnull(b.num, 0) as win,
                (ifnull(b.num, 0) / a.num * 100) as winRate
                from (
                    select
                    participantType,
                    participantId,
                    appUserId,
                    count(*) as num
                    from t_world_cup_competitor
                    where 1 = 1
                    <if test="null != appUserIds and appUserIds.size() > 0">
                        and appUserId in
                        <foreach collection="appUserIds" item="iten" index="index" open="(" separator="," close=")">
                            #{iten}
                        </foreach>
                    </if>
                    group by participantType, participantId, appUserId
                ) as a
                left join (
                    select
                    participantType,
                    participantId,
                    appUserId,
                    count(*) as num
                    from t_world_cup_competitor
                    where matchResult = 1
                    <if test="null != appUserIds and appUserIds.size() > 0">
                        and appUserId in
                        <foreach collection="appUserIds" item="iten" index="index" open="(" separator="," close=")">
                            #{iten}
                        </foreach>
                    </if>
                    group by participantType, participantId, appUserId
                ) as b on (a.participantId = b.participantId and a.participantType = b.participantType)
            ) as aa order by aa.totalSession desc
        ) as bb, (SELECT @row_num := 0) AS r
    </select>
    <select id="worldCupRecordsListCount" resultType="int">
        select count(*) from {
            select
            participantType,
            participantId,
            appUserId,
            from t_world_cup_competitor
            where 1 = 1
            <if test="null != appUserIds and appUserIds.size() > 0">
                and appUserId in
                <foreach collection="appUserIds" item="iten" index="index" open="(" separator="," close=")">
                    #{iten}
                </foreach>
            </if>
            group by participantType, participantId, appUserId
        } as aa
    </select>
</mapper>