File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ -- This SQL query retrieves the number of unique domains and total domains for each adlist from the vw_gravity view.
2+ -- It calculates the uniqueness percentage and orders the results by this percentage in ascending order.
3+
4+ SELECT
5+ adlist_id,
6+ COUNT (DISTINCT domain) AS unique_domains,
7+ COUNT (domain) AS total_domains,
8+ ROUND(CAST(COUNT (DISTINCT domain) AS FLOAT) / COUNT (domain) * 100 , 2 ) AS uniqueness_percent
9+ FROM
10+ vw_gravity
11+ GROUP BY
12+ adlist_id
13+ ORDER BY
14+ uniqueness_percent ASC ;
15+
16+
17+ -- Example output:
18+ -- adlist_id unique_domains total_domains uniqueness_percent
19+ -- 7 30873 31461 98.13
20+ -- 6 42363 42536 99.59
21+ -- 1 106610 106611 100.0
22+ -- 2 2194 2194 100.0
23+ -- 3 162079 162079 100.0
24+ -- 4 319548 319548 100.0
25+ -- 5 307383 307383 100.0
Original file line number Diff line number Diff line change 1+ -- This SQL query calculates the percentage of globally unique domains in each adlist from the vw_gravity view.
2+ -- Run trim-domain.sql before executing this query to ensure that the domain field is clean and trimmed.
3+ SELECT
4+ g1 .adlist_id ,
5+ COUNT (* ) AS total_domains,
6+ SUM (CASE WHEN dup_counts .domain_count = 1 THEN 1 ELSE 0 END) AS globally_unique_domains,
7+ ROUND(SUM (CASE WHEN dup_counts .domain_count = 1 THEN 1 .0 ELSE 0 END) / COUNT (* ) * 100 , 2 ) AS uniqueness_percent
8+ FROM
9+ vw_gravity g1
10+ JOIN (
11+ SELECT domain, COUNT (DISTINCT adlist_id) AS domain_count
12+ FROM vw_gravity
13+ GROUP BY domain
14+ ) dup_counts ON g1 .domain = dup_counts .domain
15+ GROUP BY
16+ g1 .adlist_id
17+ ORDER BY
18+ uniqueness_percent DESC ;
19+
20+ -- Example output:
21+ -- adlist_id total_domains globally_unique_domains uniqueness_percent
22+ -- 4 319548 319548 100.0
23+ -- 2 2194 2194 100.0
24+ -- 7 31461 29665 94.29
25+ -- 1 106611 100485 94.25
26+ -- 6 42536 38253 89.93
27+ -- 5 307383 249377 81.13
28+ -- 3 162079 96220 59.37
Original file line number Diff line number Diff line change 1+ -- Trim leading and trailing characters from the domain field in the gravity table
2+ UPDATE gravity
3+ SET domain = TRIM (
4+ TRIM (SUBSTR(domain, CASE WHEN domain LIKE ' ||%' THEN 3 ELSE 1 END), ' ^' )
5+ )
6+ WHERE adlist_id = 26 ;
You can’t perform that action at this time.
0 commit comments