幸运24-统计-个人统计-调整sql去适应sharding的合并计算

This commit is contained in:
2025-08-12 17:27:25 +08:00
parent bbd3353b0f
commit 50c49e5619

View File

@@ -59,17 +59,17 @@
<select id="listPersonal" resultType="com.accompany.sharding.vo.Lucky24PersonalStat">
select #{zoneDate} as `date`,
#{partitionId} as partition_id,
0 as pool_type,
r.uid,
ifnull(sum(gift_num * gift_gold_price),0) `totalInput`,
ifnull(sum(win_gold_num),0) `totalOutput`,
ifnull(sum(gift_num * gift_gold_price) - sum(win_gold_num),0) `production`,
ifnull(sum(win_gold_num) / sum(gift_num * gift_gold_price),0) `productionRatio`,
ifnull(sum(gift_num * gift_gold_price) / count(*),0) `avgInput`,
count(*) `num`,
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
ifnull(count((case when win_gold_num > 0 then r.uid else null end)) / count(*),0) `winRate`
#{partitionId} as partition_id,
0 as pool_type,
r.uid,
sum(gift_num * gift_gold_price) `totalInput`,
sum(win_gold_num) `totalOutput`,
sum(gift_num * gift_gold_price) - sum(win_gold_num) `production`,
sum(win_gold_num) / sum(gift_num * gift_gold_price) `productionRatio`,
sum(gift_num * gift_gold_price) / count(*) `avgInput`,
count(*) `num`,
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
count((case when win_gold_num > 0 then r.uid else null end)) / count(*) `winRate`
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
<if test="null != userRechargeLevel and '' != userRechargeLevel">
inner join users u on r.uid = u.uid
@@ -77,7 +77,7 @@
</if>
where r.partition_id = #{partitionId}
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
and r.create_time >= #{startTime} and r.create_time &lt;= #{endTime}
and r.create_time between #{startTime} and #{endTime}
<if test="null != uid">
and r.uid = #{uid}
</if>
@@ -89,14 +89,14 @@
#{partitionId} as partition_id,
r.pool_type,
r.uid,
ifnull(sum(gift_num * gift_gold_price),0) `totalInput`,
ifnull(sum(win_gold_num),0) `totalOutput`,
ifnull(sum(gift_num * gift_gold_price) - sum(win_gold_num),0) `production`,
ifnull(sum(win_gold_num) / sum(gift_num * gift_gold_price),0) `productionRatio`,
ifnull(sum(gift_num * gift_gold_price) / count(*),0) `avgInput`,
sum(gift_num * gift_gold_price) `totalInput`,
sum(win_gold_num) `totalOutput`,
sum(gift_num * gift_gold_price) - sum(win_gold_num) `production`,
sum(win_gold_num) / sum(gift_num * gift_gold_price) `productionRatio`,
sum(gift_num * gift_gold_price) / count(*) `avgInput`,
count(*) `num`,
count((case when win_gold_num > 0 then r.uid else null end)) `winNum`,
ifnull(count((case when win_gold_num > 0 then r.uid else null end)) / count(*),0) `winRate`
count((case when win_gold_num > 0 then r.uid else null end)) / count(*) `winRate`
from lucky_24_record r force index (lucky_24_record_partition_id_pool_type_create_time_uid_index)
<if test="null != userRechargeLevel and '' != userRechargeLevel">
inner join users u on r.uid = u.uid
@@ -104,7 +104,7 @@
</if>
where r.partition_id = #{partitionId}
and r.pool_type in <foreach collection="poolTypeList" item="poolType" separator="," open="(" close=")">#{poolType}</foreach>
and r.create_time >= #{startTime} and r.create_time &lt;= #{endTime}
and r.create_time between #{startTime} and #{endTime}
<if test="null != uid">
and r.uid = #{uid}
</if>