Question: Write a query to select the total population in each age group. Use the query from Step 6 as a subquery to find each type
- Write a query to select the total population in each age group.
- Use the query from Step 6 as a subquery to find each type of education attained by the population in that age group and the fraction of the population of that age group that has that educational attainment. Label the fraction column output as coefficient. For instance, the fraction of the population in age group 00 - 17 who has an education attainment of Bachelor's degree or higher is 0.0015, which is the coefficient.
- Create a demographics table from the SQL query from Step 7.
- Create a query on the pop_proj table which shows the population count by date_year and age.
- Use that query from Step 9 as a subquery and join it to the demographics table using the following case statement:
demographics.age = case when temp_pop.age < 18 then '00 to 17' when temp_pop.age > 64 then '65 to 80+' else '18 to 64' end
temp_pop is an alias for the subquery. Use the following calculation for the demand output:
round(sum(temp_pop.total_pop * demographics.coefficient)) as demand
Output the demand grouped by year and education level.
Categories of the tables are as follows-
educational_attainment- Year, Age, Gender, Educational_Attainment, Personal_Income, Population_Count
pop_proj- fips, county, year, age, pop_female, pop_male, pop_total
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
