I have three tables:
First Block of Query: it computes the impressions
Second Block of Query: it computes the conversions
Then I am joining to create another table
create table stage_II_final_suzuki_1648436600 as
select a.*,b.conversions, b.total_users
from tmp.stage_II_imps_suzuki_1648436600 a
join
tmp.stage_II_conversions_suzuki_1648436600 b
on a.domain = b.domain
and a.ad_position = b.ad_position
and a.browser_id = b.browser_id
and a.hour_of_day = b.hour_of_day
and a.day_of_week = b.day_of_week
and a.exchange_id = b.exchange_id
and a.device_type = b.device_type
ORDER BY b.total_users;
The output is:
domain, ad_position, hour_of_day, browser_id, exchange_id, day_of_week, device_type, impressions, conversions, total users
Now, how shall I return feature values (~20%) of which caters ~80% of users.?
Features: domain, ad_position, browser_id, hour_of_day, day_of_week, exchange_id, device_type
so for an example,
browser-user share chrome - 55% Mozila FF - 17% MS Edge - 12% Safari - 15% duck duck go - 0.5% Then result should be Chrome, Mozila and Safari
and similarly for all features
This query uses
sum(share) over (order by share desc)
in a sub-query to get the running total of market share.It includes the minimum number of browsers for the total market share to be over 80%.
NB This is tested on dbFiddle SQL server but I believe that Google bigQuery (used by google-ads-data-hub) has all the functions used.
db<>fiddle here