Hive表嵌套查询

  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;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值