top of page
Search

US Household Income Exploratory (SQL)

Feb 19, 2025
5 min read

Updated: Mar 5, 2025

This is my project analyzing a US Household Income Exploratory in SQL for Data Analysis. In this project we will walk through the process used for the cleaning the data and answering questions from our client.




Breaking Down the U.S. Household Income Data Cleaning Process


Step 1: Understanding the Data

Before making any changes, we first inspect the data in the two tables:

SELECT *  
FROM us_project.us_household_income;


SELECT * 
FROM us_project.ushouseholdincome_statistics;


This helps us understand the structure of the dataset and see if there are any errors.




Step 2: Fixing Column Names

We noticed that one of the column names in ushouseholdincome_statistics had incorrect characters, making it hard to read. To fix this, we renamed the column:

ALTER TABLE us_project.ushouseholdincome_statistics 
RENAME COLUMN `id` TO `id`;

Now, the column has a clear and readable name.


Step 3: Checking for Duplicates

To ensure data quality, we need to check if there are duplicate id values in the us_household_income table.

SELECT id, COUNT(id) AS duplicatefinder
FROM us_project.us_household_income
GROUP BY id
HAVING COUNT(id) > 1;

This query finds any id values that appear more than once, indicating duplicate rows.




Step 4: Identifying Duplicate Rows

To locate duplicate rows in more detail, we use the ROW_NUMBER ( ) function:

SELECT *
FROM (
    SELECT row_id, id,
    ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS row_num
    FROM us_project.us_household_income
) subqueryforduplicates
WHERE row_num > 1;

This assigns a row number to each duplicate entry. Any row where row_num > 1 is a duplicate.




Step 5: Deleting Duplicate Rows

Now that we have identified duplicates, we delete them:

DELETE FROM us_project.us_household_income
WHERE row_id IN ( 
    SELECT row_id
    FROM (
        SELECT row_id, id,
        ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS row_num
        FROM us_project.us_household_income
    ) subqueryforduplicates
    WHERE row_num > 1
);

This removes all duplicate rows, keeping our data clean.



Step 6: Verifying Duplicate Removal

To confirm that all duplicate rows were successfully deleted, we run the duplicate check query again:

SELECT *
FROM (
    SELECT row_id, id,
    ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS row_num
    FROM us_project.us_household_income
) subqueryforduplicates
WHERE row_num > 1;

Since no results appear, we have successfully removed all duplicates!



Step 7: Checking for Incorrect Data

Now, we check for potential corrupt or incorrect data. Specifically, we look at the AWater column (which represents water area in a county). Some values are 0, so we check if they make sense:

SELECT Aland, AWater
FROM us_project.us_household_income
WHERE (AWater = 0 OR AWater = '' OR AWater IS NULL)
AND (Aland = 0 OR Aland = '' OR Aland IS NULL);

This checks if both Aland (land area) and AWater (water area) are 0 or empty.

Result: The query confirmed that counties with AWater = 0 were land-only counties, meaning the data is correct.



Step 8: Cleaning Duplicate Data in the "Type" Column

We also noticed that the Type column contained inconsistent values. Some counties were labeled as "Boroughs", while others were labeled "Borough" (singular).To fix this inconsistency, we update the values:

UPDATE us_project.us_household_income
SET Type = 'Borough'
WHERE Type = 'Boroughs';

Now, all boroughs are consistently labeled.




Step 9: Final Data Check

After cleaning, we review the dataset one last time to ensure everything looks good:

SELECT * 
FROM us_project.us_household_income;

The data is now clean and ready for analysis! 

Summary of What We Did

  1. Checked the dataset by selecting all records.

  2. Fixed column names to be more readable.

  3. Found and deleted duplicate rows to ensure unique data.

  4. Verified that no incorrect data was present in land and water area columns.

  5. Standardized values in the "Type" column to remove inconsistencies.

  6. Final check to confirm the dataset is clean and ready for analysis.





Breaking Down the U.S. Household Income Analysis (SQL)

In this analysis, we're using SQL queries to explore U.S. household income data and identify key insights. Here's a step-by-step breakdown of what we're analyzing and what each query does.


Step 1: Understanding the Data

Before diving into the analysis, we first inspect both tables to understand their structure:

SELECT * FROM us_project.us_household_income;
SELECT * FROM us_project.ushouseholdincome_statistics;

This allows us to see the available columns and how they are related.



Step 2: Identifying the Top States by Land and Water Area

We want to find the top 5 states with the most land area and the most water area (which includes lakes and oceans).

Finding the Top 5 States with the Most Land

SELECT State_Name, SUM(Aland) AS Land, SUM(AWater) AS Water
FROM us_project.us_household_income
GROUP BY State_Name
ORDER BY Land DESC
LIMIT 5;

This tells us which states have the largest land areas.

Finding the Top 5 States with the Most Water

SELECT State_Name, SUM(Aland) AS Land, SUM(AWater) AS Water
FROM us_project.us_household_income
GROUP BY State_Name
ORDER BY SUM(AWater) DESC
LIMIT 5;

This tells us which states have the largest water areas.



Step 3: Finding States with the Highest and Lowest Household Income

We now look at average household income by state using both the Mean and Median income values.

Finding the Top 10 States with the Lowest Household Income

SELECT u.State_Name, ROUND(AVG(us.Mean),1), ROUND(AVG(us.Median),1)
FROM us_project.us_household_income u 
INNER JOIN us_project.ushouseholdincome_statistics us
ON u.id = us.id 
WHERE Mean <> 0
GROUP BY u.State_Name
ORDER BY Avg_Mean ASC  -- Sorting by average income in ascending order
LIMIT 10;

This tells us which states have the lowest household income on average.

Finding the Top 10 States with the Highest Household Income

SELECT u.State_Name, ROUND(AVG(us.Mean),1), ROUND(AVG(us.Median),1)
FROM us_project.us_household_income u 
INNER JOIN us_project.ushouseholdincome_statistics us
ON u.id = us.id 
WHERE us.Mean <> 0
GROUP BY u.State_Name
ORDER BY 2 DESC  -- Sorting by highest average income
LIMIT 10;

This tells us which states have the highest household income on average.




Step 4: Identifying Household Income by Type of Housing

We now analyze income levels based on different household types.

Finding the Top 5 Household Types with the Highest Average Income

SELECT Type, COUNT(Type), ROUND(AVG(us.Mean),1), ROUND(AVG(us.Median),1)
FROM us_project.us_household_income u 
INNER JOIN us_project.ushouseholdincome_statistics us
ON u.id = us.id 
WHERE Mean <> 0
GROUP BY Type
HAVING COUNT(Type) > 20
ORDER BY 3 DESC  -- Sorting by highest income
LIMIT 5;

This tells us which household types tend to have the highest income.

Finding the Top 5 Household Types with the Lowest Average Income

SELECT Type, COUNT(Type), ROUND(AVG(us.Mean),1), ROUND(AVG(us.Median),1)
FROM us_project.us_household_income u 
INNER JOIN us_project.ushouseholdincome_statistics us
ON u.id = us.id 
WHERE us.Mean <> 0
GROUP BY Type
HAVING COUNT(Type) > 20
ORDER BY 3  -- Sorting by lowest income
LIMIT 5;

This tells us which household types tend to have the lowest income.



Step 5: Finding the Highest Income Cities in the U.S.

We also analyze household income at the city level.

Finding the Top 15 Cities with the Highest Household Income

SELECT u.State_Name, City, ROUND(AVG(us.Mean),1) AS city_income_avg, ROUND(AVG(Median),1) AS city_medianincome_avg
FROM us_project.us_household_income u 
INNER JOIN us_project.ushouseholdincome_statistics us
ON u.id = us.id 
WHERE us.Mean <> 0
GROUP BY u.State_Name, City
ORDER BY 3 DESC  -- Sorting by highest city income
LIMIT 15;

This tells us which U.S. cities have the highest average household income.


Final Thoughts and Insights

  • States with the most land and water: The U.S. states with the largest land and water areas were identified.

  • Income disparities by state: We found which states have the highest and lowest household incomes.

  • Household income by type: Some household types earn significantly more than others.

  • City-level income: Certain cities have much higher income levels than others.


Final Summary

This project provided valuable insights into U.S. household income trends through comprehensive SQL-based data analysis. We explored key economic factors, including state and city-level income distributions, land and water area comparisons, and income variations by household type. By cleaning and analyzing the data, we uncovered meaningful patterns that can help stakeholders make informed, data-driven decisions.


This concludes our U.S. Household Income Exploratory Data Analysis in SQL. We hope this walkthrough gave you a clear understanding of my process and findings.



Author: Merrill Kitchens



 
 
 

1 Comment


Darri Harber
Darri Harber
Jan 18

Congrats, well written.

Like
vvffg_5_edited_edited.png

Data analytics professional with a recent BBA in Business Economics. Proficient in data analysis platforms including MySQL, Google Spreadsheets, Excel, Tableau, Python, R, Pandas, Azure, AWS, Big Query, Econometrics, and data visualization. Adept at extracting actionable insights and presenting data-driven recommendations to stakeholders. Eager to leverage technical skills and academic knowledge to drive impactful business decisions.

•    SQL (MySQL, PostgreSQL, Big Query)   
•    Tableau (Advanced Data Preparation, Creating Dashboards, Data Cleaning)
•    Python (Pandas, NumPy, Matplotlib, Seaborn)    
•    Excel (VLOOKUP, Pivot Tables, Conditional Formatting, Automation)    
•    Microsoft Power BI      
•    Google Spreadsheets
•    Aws
•    Azure           
•    Econometrics
•    Microsoft Office: Proficient in Outlook, Word, Excel, PowerPoint Microsoft Navision
•    Knowledge: Educated in Economic Concepts, Financial Analytical Skills

 

Education:

Bachelor of Business Administration, Business Economics at Georgia State University      

- (3.5 GPA): Data Collection & Analysis, Data Structures & Algorithms, Economic Research

 

Certifications:
•    Analyst Builder for Data Analyst Certification: (Advanced MySQL for Data Analysis, Pandas, Python, Tableau)
•    Google Data Analytics Certification: (Advanced Excel for Automation, R, Big Query) 
•    Market Research Foundations (Market Research Program)

  • GitHub
  • LinkedIn
bottom of page