1.手电筒当天下载自定义活跃:
SELECT user_dim.app_info.app_instance_id FROM [flashlight35-6aae4:com_scroll_sos_flashlight_ANDROID.app_events_20170328] WHERE (event_dim.name='自定义真活跃' OR event_dim.params.key='自定义真活跃') AND user_dim.app_info.app_instance_id IN ( SELECT user_dim.app_info.app_instance_id FROM [flashlight35-6aae4:com_scroll_sos_flashlight_ANDROID.app_events_20170328] WHERE event_dim.name = 'first_open' ) GROUP BY user_dim.app_info.app_instance_id ;
Q: (event_dim.name='自定义真活跃'
OR event_dim.params.key='自定义真活跃')
使用时用哪个?
A:使用时会有一个记录表,按照表格查询再写
Q:为什么WHERE处用AND,不直接AND两个where?
A:一个user对应的event是一个数组形式,或者同一个用户的event是不同log记录,应该是找出人群再AND
2.查询一个国家有多少用户:
SELECT user_dim.geo_info.country, COUNT(user_dim.geo_info.country )AS cnt FROM ( SELECT user_dim.app_info.app_instance_id, user_dim.geo_info.country, COUNT(user_dim.geo_info.country )AS cnt FROM [antivirus-e1deb:com_androapplite_antivirus_antivirusapplication_ANDROID.app_events_20180118] GROUP BY user_dim.app_info.app_instance_id, user_dim.geo_info.country ) GROUP BY user_dim.geo_info.country ORDER BY cnt DESC
在From后面写是相当于形成了一个临时的列表,COUNT(user_dim.geo_info.country )中也可以写成user_dim.app_info.app_instance_id,*,其实只是相当于一条数据。