【SQL】搜狐畅游2019校招笔试题-数据分析师

数据库有两张表, 

A表为游戏登录表,用户每次上线记录一条:dt(登录日期),servertime(登录时间),userid(用户id),rolelevel(用户等级,int);

B表为游戏充值表,用户每次充值记录一条:dt(充值日期),servertime(充值时间),userid(用户id),money(充值金额,int)

请查出: 

1)2018年9月1日~2018年9月7日每天的活跃用户数。指标说明:日活跃用户数指当天登录用户数去重。

2)2018年9月1日~2018年9月7日每天的新增用户数(说明:18年 9月1日为游戏上线第一天,即登录表是从18年9月1日开始有记录)。指标说明:某账号首次登陆游戏算作该游戏的一个新增账号数

3)2018年9月1日当天,20级以上用户的付费总金额。

1)

select dt,count(distinct userid) cnt from A

    where dt between '2018-09-01' and '2018-09-07'

group by dt

2)

select dt,count(distinct userid) new_user

(select userid,min(dt) register_date from A

    where dt between '2018-09-01' and '2018-09-07')

group by dt

3)

    select sum(money)  from

     (select distinct userid from A

     where rolelevel>=20)C

    left join

    B

    on C.userid=B.userid

    where B.dt='2018-09-01'

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。