-- 1.新增玩家SELECTCOUNT(distinct user_id)as'新增玩家数量'FROM
tap_fun_test;SELECTCOUNT(distinct user_id)as'新增付费玩家数量'FROM
tap_fun_test
WHERE pay_price>0;SELECT b.新增付费玩家数量/a.新增玩家数量 as'付费玩家占比'from(SELECTCOUNT(distinct user_id)as'新增玩家数量'FROM
tap_fun_test)as a
join(SELECTCOUNT(distinct user_id)as'新增付费玩家数量'FROM
tap_fun_test
WHERE pay_price>0)as b;SELECTdate(register_time)as'日期',COUNT(DISTINCT user_id)as'每日新增玩家数'FROM tap_fun_test
GROUPBYdate(register_time);SELECTdate(register_time)as'日期',COUNT(DISTINCT user_id)as'每日新增付费玩家数'FROM tap_fun_test
where pay_price>0GROUPBYdate(register_time);#debug 执行顺序where>group by;#2玩家活跃度selectavg(avg_online_minutes)as 全部玩家平均在线时长
from tap_fun_test;selectavg(avg_online_minutes)as 付费玩家平均在线时长
from tap_fun_test where pay_price>0;#分布:min,下四分位数,中位数,上四位数,max-- 下四位数,中位数,上四分位数位置idSELECTround(COUNT(distinct user_id)/4)as id_下四分位,round(COUNT(distinct user_id)/2)as id_中位,round(COUNT(distinct user_id)*0.75)as id_上四分位
from tap_fun_test;SELECTround(COUNT(distinct user_id)/4)as id_下四分位,round(COUNT(distinct user_id)/2)as id_中位,round(COUNT(distinct user_id)*0.75)as id_上四分位
from tap_fun_test
where pay_price>0;-- min,下四分位数,中位数,上四位数,maxSELECTmin(avg_online_minutes)as min,(SELECT avg_online_minutes from tap_fun_test
ORDERBY avg_online_minutes limit207233,1)as 下四分位数,(SELECT avg_online_minutes from tap_fun_test
ORDERBY avg_online_minutes limit414466,1)as 中位数,(SELECT avg_online_minutes from tap_fun_test
ORDERBY avg_online_minutes limit621700,1)as 上四分位数,max(avg_online_minutes)as max
from
tap_fun_test;SELECTmin(avg_online_minutes)as min,(SELECT avg_online_minutes from tap_fun_test where pay_price>0ORDERBY avg_online_minutes limit4886,1)as 下四分位数,(SELECT avg_online_minutes from tap_fun_test where pay_price>0ORDERBY avg_online_minutes limit9774,1)as 中位数,(SELECT avg_online_minutes from tap_fun_test where pay_price>0ORDERBY avg_online_minutes limit14661,1)as 上四分位数,max(avg_online_minutes)as max
from
tap_fun_test
where pay_price>0;#debug:-- 用where user_id=207234寻找4分位数是不对的,这里选的时候使用了distinct,所以行数不再等于id数-- limit 分页查询的查询需要位数-1#3 玩家付费情况#AU-- SELECT distinct user_id as '活跃用户id'FROM tap_fun_test-- where avg_online_minutes>=15;SELECTcount(DISTINCT user_id)as AU活跃用户数 FROM tap_fun_test
where avg_online_minutes>=15;#APASELECTcount(DISTINCT user_id)as APA FROM tap_fun_test
where avg_online_minutes>=15and pay_price>0;#ARPUSELECT(SELECTsum(pay_price)from tap_fun_test)/count(distinct user_id)as ARPU
from tap_fun_test
where avg_online_minutes>=15;#ARPPUSELECT(SELECTsum(pay_price)from tap_fun_test)/count(distinct user_id)as ARPPU
from tap_fun_test
where avg_online_minutes>=15and pay_price>0;#PURSELECT(SELECTcount(distinct user_id)from tap_fun_test WHERE pay_price>0)/count(distinct user_id)as PUR
from tap_fun_test
where avg_online_minutes>=15and pay_price>0;#4玩家游戏习惯#PVP,AU SELECTavg(pvp_battle_count)as 平均pvp次数,sum(pvp_lanch_count)/sum(pvp_battle_count)as 主动PVP概率,sum(pvp_win_count)/sum(pvp_battle_count)as pvp胜利概率
from tap_fun_test where avg_online_minutes>=15;#PVP,APASELECTavg(pvp_battle_count)as 平均pvp次数,sum(pvp_lanch_count)/sum(pvp_battle_count)as 主动PVP概率,sum(pvp_win_count)/sum(pvp_battle_count)as pvp胜利概率
from tap_fun_test where avg_online_minutes>=15;#PVE,AU SELECTavg(pve_battle_count)as 平均pve次数,sum(pve_lanch_count)/sum(pve_battle_count)as 主动PVE概率,sum(pve_win_count)/sum(pve_battle_count)as pve胜利概率
from tap_fun_test where avg_online_minutes>=15;#PVE,APASELECTavg(pve_battle_count)as 平均pve次数,sum(pve_lanch_count)/sum(pve_battle_count)as 主动PVE概率,sum(pve_win_count)/sum(pve_battle_count)as pve胜利概率
from tap_fun_test where avg_online_minutes>=15and pay_price>0;-- debug -- 所有活跃玩家需要sum一下