1. 要求:查询出局数100局及以上的玩家名称和占全体玩家的百分比
  2. 通过greatest函数与case then语句完成嵌套查询
  • 通过case when语句过滤出年龄段符合且将不符合年龄的赋值为0局游戏局数
  • 过滤出games_count表后,再过滤出100局及以上 有则1无则0统数
  • 最后将得出的结果查询出符合条件与总数量得出百分比

player-玩家 player_name 玩家名称 player_age 玩家年龄

select t.*,t.count_100/t.tcount rate_100 from(
select player_name,count(*)tcount,sum(case when games_count >= 100 then 1 else 0)count_100 from(
select player_name,greatest(
case when player_age>=18 and play_age<=22 then games else 0 end
)games_count 
from table where hour=2019032000
)count_all 
where games_count > 0 group by player_name
)t;