from ( select year, month, day, referer_class, sum(view_count) over (partition by year, month, day, referer_class) / sum(view_count) over (partition by year, month, day) as ratio from projectview_hourly where year > 2016 and project = 'id.wikipedia' and access_method = 'mobile web' and agent_type = 'user') t1 select distinct * order by referer_class, year, month, day limit 20000 ;