Skip to content

How have American baby name tastes changed since 1920? Which names have remained popular for over 100 years, and how do those names compare to more recent top baby names? These are considerations for many new parents, but the skills you'll practice while answering these queries are broadly applicable. After all, understanding trends and popularity is important for many businesses, too!

You'll be working with data provided by the United States Social Security Administration, which lists first names along with the number and sex of babies they were given to in each year. For processing speed purposes, the dataset is limited to first names which were given to over 5,000 American babies in a given year. The data spans 101 years, from 1920 through 2020.

The Data

baby_names

columntypedescription
yearintyear
first_namevarcharfirst name
sexvarcharsex of babies given first_name
numintnumber of babies of sex given first_name in that year
Spinner
DataFrameas
usa_baby_names
variable
-- Run this code to view the data in baby_names
SELECT *
FROM baby_names
LIMIT 5;
Spinner
DataFrameas
name_types
variable
-- Use this table for the answer to question 1:
-- List the overall top five names in alphabetical order and find out if each name is "Classic" or "Trendy."
select first_name,
	sum(num) as sum,
case when count(distinct first_name) >= 50 then 'Classic'
	else 'Trendy' end as popularity_type
from public.baby_names
group by public.baby_names.first_name
order by first_name asc
limit 5

Spinner
DataFrameas
top_20
variable
-- Use this table for the answer to question 2:
-- What were the top 20 male names overall, and how did the name Paul rank?
with ranked_names as(	
    select first_name,
           sum(num) as total,
           rank() over(order by sum(num) desc) as rank	
    from public.baby_names
    where sex = 'M'
    group by first_name
)
select first_name,
       total as sum,
       rank as name_rank
from ranked_names
limit 20;
Spinner
DataFrameas
a_names
variable
-- Use this table for the answer to question 3:
-- Which female names appeared in both 1920 and 2020?

with twentynames as(
	select first_name,
		sum(num) as occurences
	from public.baby_names
	where year = '1920'
		and sex = 'F'
	group by first_name
),

twentytwentynames as (
	select first_name,
	sum(num) as occurences
	from public.baby_names
	where year = '2020'
	and sex = 'F'
	group by first_name
)

select nn.first_name,
	nn.occurences + tn.occurences as total_occurrences
from twentynames nn
inner join twentytwentynames tn
on nn.first_name = tn.first_name