SEO Analytics in SQL for Beginners: A step-by-step tutorial

Step 1. Setup your database

This is Postico.

Step 2: Create your table(s)

CREATE TABLE positions (
keyword character varying,
position numeric,
previous_position numeric,
search_volume numeric,
keyword_difficulty numeric,
cpc numeric,
url character varying,
traffic numeric,
traffic_pct numeric,
traffic_cost numeric,
competition numeric,
number_of_results numeric,
trends character varying,
timestamp timestamp without time zone,
serp_features_by_keyword character varying,
keyword_intents character varying,
domain character varying
);
Dark mode… Looks like it was nighttime.

Step 3: Import your data

Still nighttime…

Step 4: Get to know the data

What are the highest search volume keywords?

select * 
from positions p
order by p.search_volume desc
Now it’s the next day.

What’s the distribution of search volume for these keywords?

Let’s group the keywords by their order of magnitude with log base 10.

select ceiling(log(10, p.search_volume)),
count(*)
from positions p
group by 1
order by 1
It’s all light from here…

Step 5: Real SEO analytics in SQL!

How many keywords have more than one URL ranking for them? (cannibalization risks)

select p.keyword,
max(p.search_volume),
count(distinct p.url),
min(p.position),
max(p.position),
string_agg(p.url, ', ')
from positions p
group by 1
having count(distinct p.url) > 1
order by 2 desc

What Knowledge Graph Entities are represented on this website?

select p.keyword,
max(p.search_volume),
count(distinct p.url),
min(p.position),
max(p.position),
string_agg(p.url, ', ')
from positions p
where p.serp_features_by_keyword ilike '%Knowledge panel%'
group by 1
order by 2 desc

Step 6: To infinity and beyond! ⚡

Adblock test (Why?)