Skip to content

Commit a26f90a

Browse files
authored
Create 01322-ads-performance.sql
1 parent b6034be commit a26f90a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

01322-ads-performance.sql

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- my first intuition was to create 2 ctes- 1 with click count and 1 with (click + view) count using WHERE filter
2+
-- but this approach will not work because we cannot filter rows because we want all ad_ids, even those who were not clicked/viewed
3+
4+
-- so we need to use case statement or the below approach
5+
6+
select ad_id,
7+
ifnull(round((sum(action = 'Clicked'))/(sum(action = 'Clicked') + sum(action = 'Viewed'))*100, 2), 0) as ctr
8+
from Ads
9+
group by 1
10+
order by 2 desc, 1
11+
12+
-- facebook- 1

0 commit comments

Comments
 (0)