Question: I am trying to run a JOIN SQL script for two different data sets. I have US County data from 2000 and 2010, and in
I am trying to run a JOIN SQL script for two different data sets. I have US County data from 2000 and 2010, and in both there are a few counties that are excluded from the other because they are no longer geographical counties. I am trying to use appropriate JOIN and NULL values to identify which counties don't exist in both tables. Using this query, it returns the all the same values from both tables. However, I am only looking to identify the null values from each
SELECT c2010.geo_name, c2010.state_us_abbreviation AS state, c2010.p0010001 AS pop_2010, c2000.p0010001 AS pop_2000, c2010.p0010001 - c2000.p0010001 AS raw_change, round( (CAST(c2010.p0010001 AS numeric(8,1)) - c2000.p0010001)/ c2000.p0010001 * 100, 1 ) AS pct_change FROM us_counties_2010 c2010 LEFT JOIN us_counties_2000 c2000 ON c2010.state_fips = c2000.state_fips AND c2010.county_fips = c2000.county_fips AND c2010.p0010001 <> c2000.p0010001 ORDER BY pct_change DESC;
I have been trying to add this line of code to what I already have, but it does not work.
SELECT c2010.geo_name, c2010.state_us_abbreviation AS state, c2010.p0010001 AS pop_2010, c2000.p0010001 AS pop_2000, c2010.p0010001 - c2000.p0010001 AS raw_change, round( (CAST(c2010.p0010001 AS numeric(8,1)) - c2000.p0010001)/ c2000.p0010001 * 100, 1 ) AS pct_change FROM us_counties_2010 c2010 LEFT JOIN us_counties_2000 c2000 ON c2010.state_fips = c2000.state_fips AND c2010.county_fips = c2000.county_fips AND c2010.p0010001 <> c2000.p0010001 WHERE c2010.geo_name IS NULL <---------------------------------------ADDED CODE ORDER BY pct_change DESC;
I'm thinking that I do not have my WHERE statement correct? Is the primary key I used incorrect?
I also need a query that uses percentile_cont to determine the median of percent change in county population.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
