US Household Income Exploratory (SQL)
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.
Link To Code Cleaning the Data: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/USHouseHoldIncomeDataCleaning.sql
Link To Code Solving the Problems Within Cleaned Data: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/Data%20For%20US%20HOUSEHOLD%20INCOME%20Analysis%20Project.sql
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
Checked the dataset by selecting all records.
Fixed column names to be more readable.
Found and deleted duplicate rows to ensure unique data.
Verified that no incorrect data was present in land and water area columns.
Standardized values in the "Type" column to remove inconsistencies.
Final check to confirm the dataset is clean and ready for analysis.
Link To Code Cleaning the Data: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/USHouseHoldIncomeDataCleaning.sql
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.
Link To Code Solving the Problems Within Cleaned Data: https://github.com/mkitchens5/Merrill-Portfolio/blob/main/Data%20For%20US%20HOUSEHOLD%20INCOME%20Analysis%20Project.sql
Author: Merrill Kitchens




Congrats, well written.