<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yunzhi.marketing.redpack.mapper.TaRedPacketHistoryMapper">


    <select id="getRanking" resultType="com.yunzhi.marketing.redpack.entity.TaRedPacketHistory">
        SELECT
        t.helpPersonNum as help_person_num,
        t.target_miniapp_person,
        p.nickname,
        p.avatarurl
        FROM
        ( SELECT count( 1 ) AS helpPersonNum, target_miniapp_person FROM ta_red_packet_history WHERE activity_id = #{activityId} AND org_id = #{orgId} GROUP BY target_miniapp_person ) t
        LEFT JOIN ta_person p ON t.target_miniapp_person = p.person_id
        ORDER BY
        t.helpPersonNum DESC
        limit #{top}
    </select>
</mapper>
