Highest SEO Score Pages per Domain
Beginner Mode
Scenario
You work for an SEO analytics platform and have been given a table containing information about webpages and their SEO scores.
Task
Write a Snowflake SQL query that:
- For each domain in
{{ ref("pages") }}, finds the URL and score of the page with the highestseo_score(output ashighest_seo_pageandhighest_seo_score) - Finds the URL and score of the single page with the highest
seo_scoreacross all domains (output asoverall_highest_pageandoverall_highest_score) - Returns one row per domain with columns:
domain,highest_seo_page,highest_seo_score,overall_highest_page,overall_highest_score - Only the domain whose best page is also the global best should have
overall_highest_pageandoverall_highest_scorepopulated (all other domains should haveNULLfor these columns)
Schema
pages
| Column | Type | Description |
|---|---|---|
| domain | String | The domain name of the webpage |
| url | String | The full URL of the webpage |
| seo_score | Integer | The SEO score of the webpage (0 to 100) |
Example
pages:
| domain | url | seo_score |
|---|---|---|
| acme.com | https://acme.com/about | 74 |
| acme.com | https://acme.com/blog | 89 |
| acme.com | https://acme.com/contact | 65 |
| widget.io | https://widget.io/home | 91 |
| widget.io | https://widget.io/pricing | 78 |
| spark.dev | https://spark.dev/docs | 83 |
| spark.dev | https://spark.dev/faq | 70 |
Expected Output:
| domain | highest_seo_page | highest_seo_score | overall_highest_page | overall_highest_score |
|---|---|---|---|---|
| acme.com | https://acme.com/blog | 89 | NULL | NULL |
| spark.dev | https://spark.dev/docs | 83 | NULL | NULL |
| widget.io | https://widget.io/home | 91 | https://widget.io/home | 91 |
Note: Only the domain whose best page is also the global best (
widget.iowith score 91) hasoverall_highest_pageandoverall_highest_scorepopulated. All other domains haveNULLfor these two columns.
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Cisco