R
rpw
Hi everyone,
Hmmm, how do I describe this? Springfield-1 and Springfield-2 are
"territory" names. Each of the 'Springfield' territories are defined
geographically by a combination of Counties and Zip Codes.
(e.g. Chester county is in Springfield-1, Harris county is in Springfield-2,
and Springfield county is split between both territories with zip code 12345
belonging to Springfield-1 and 12399 belonging to Springfield-2, and so on.)
I have a table for territories by county, a table for territories by zip
code, at table for demographics by county and one for demographics by zip
code.
I have created two queries: one for summing/grouping by territory out of the
'by county' tables and one for summing/grouping by territories (not in the
county territories) out of the 'by zip code' tables. Both deliver the
expected results.
My question is: How can I get the results of each query grouped together
like the sample output below?
Territory Population Income WeightedIncome
Springfield-1 1,200,356 $4564216 $45563588494
Springfield-2 2,456,548 $4568716 $48979683413
Here's the SQL for the two queries:
SELECT tblTerritoryByCounty.Territory, tblTerritoryByCounty.Franchisee,
Sum(tblPopByCounty.[2007 Estimated Population]) AS [SumOf2007 Estimated
Population], Sum(tblPopByCounty.[2007 Estimated Median HH Income]) AS
[SumOf2007 Estimated Median HH Income], Sum([2007 Estimated Population]*[2007
Estimated Median HH Income]) AS GrossIncome
FROM tblPopByCounty INNER JOIN tblTerritoryByCounty ON (tblPopByCounty.STATE
= tblTerritoryByCounty.State) AND (tblPopByCounty.County =
tblTerritoryByCounty.County)
GROUP BY tblTerritoryByCounty.Territory, tblTerritoryByCounty.Franchisee
HAVING ((Not (tblTerritoryByCounty.Franchisee)="Z-None"));
SELECT Count(tblPopByZipCode.STATE) AS CountOfSTATE,
Count(tblZipCodesByTerritory.County) AS CountOfCounty,
Count(tblZipCodesByTerritory.ZipCode) AS CountOfZipCode,
tblZipCodesByTerritory.Territory, Sum(tblPopByZipCode.POPULATION) AS
SumOfPOPULATION, Sum(tblPopByZipCode.INCOME) AS SumOfINCOME,
Sum([POPULATION]*[INCOME]) AS WeightedIncome,
tblZipCodesByTerritory.[CountByZip&County]
FROM tblPopByZipCode INNER JOIN tblZipCodesByTerritory ON
tblPopByZipCode.ZIPCODE = tblZipCodesByTerritory.ZipCode
GROUP BY tblZipCodesByTerritory.Territory,
tblZipCodesByTerritory.[CountByZip&County]
HAVING (((tblZipCodesByTerritory.[CountByZip&County])=True));
All responses are appreciated... Thanks in advance for you help and advice.
Hmmm, how do I describe this? Springfield-1 and Springfield-2 are
"territory" names. Each of the 'Springfield' territories are defined
geographically by a combination of Counties and Zip Codes.
(e.g. Chester county is in Springfield-1, Harris county is in Springfield-2,
and Springfield county is split between both territories with zip code 12345
belonging to Springfield-1 and 12399 belonging to Springfield-2, and so on.)
I have a table for territories by county, a table for territories by zip
code, at table for demographics by county and one for demographics by zip
code.
I have created two queries: one for summing/grouping by territory out of the
'by county' tables and one for summing/grouping by territories (not in the
county territories) out of the 'by zip code' tables. Both deliver the
expected results.
My question is: How can I get the results of each query grouped together
like the sample output below?
Territory Population Income WeightedIncome
Springfield-1 1,200,356 $4564216 $45563588494
Springfield-2 2,456,548 $4568716 $48979683413
Here's the SQL for the two queries:
SELECT tblTerritoryByCounty.Territory, tblTerritoryByCounty.Franchisee,
Sum(tblPopByCounty.[2007 Estimated Population]) AS [SumOf2007 Estimated
Population], Sum(tblPopByCounty.[2007 Estimated Median HH Income]) AS
[SumOf2007 Estimated Median HH Income], Sum([2007 Estimated Population]*[2007
Estimated Median HH Income]) AS GrossIncome
FROM tblPopByCounty INNER JOIN tblTerritoryByCounty ON (tblPopByCounty.STATE
= tblTerritoryByCounty.State) AND (tblPopByCounty.County =
tblTerritoryByCounty.County)
GROUP BY tblTerritoryByCounty.Territory, tblTerritoryByCounty.Franchisee
HAVING ((Not (tblTerritoryByCounty.Franchisee)="Z-None"));
SELECT Count(tblPopByZipCode.STATE) AS CountOfSTATE,
Count(tblZipCodesByTerritory.County) AS CountOfCounty,
Count(tblZipCodesByTerritory.ZipCode) AS CountOfZipCode,
tblZipCodesByTerritory.Territory, Sum(tblPopByZipCode.POPULATION) AS
SumOfPOPULATION, Sum(tblPopByZipCode.INCOME) AS SumOfINCOME,
Sum([POPULATION]*[INCOME]) AS WeightedIncome,
tblZipCodesByTerritory.[CountByZip&County]
FROM tblPopByZipCode INNER JOIN tblZipCodesByTerritory ON
tblPopByZipCode.ZIPCODE = tblZipCodesByTerritory.ZipCode
GROUP BY tblZipCodesByTerritory.Territory,
tblZipCodesByTerritory.[CountByZip&County]
HAVING (((tblZipCodesByTerritory.[CountByZip&County])=True));
All responses are appreciated... Thanks in advance for you help and advice.