T
talktobatchu
Hello
I need to store information regarding race wise population of
every county of my state year wise, which is nothing but census data. Here
the data is categorized basing on different age groups. After thinking about
a lot of options for storing this kind of data, came up with a table(s)
design as follows.
Pop_RaceAndAgeGrpWiseFrm2001C1 - this table stores data for county one. here
the ctyDistrictID is 1.
the fields are: Pop_RaceAndAgeGrpWiseFrm2001C1.EntryID,
Pop_RaceAndAgeGrpWiseFrm2001C1.ctyDistrictID,
Pop_RaceAndAgeGrpWiseFrm2001C1.RaceName,
Pop_RaceAndAgeGrpWiseFrm2001C1.statsYear,
Pop_RaceAndAgeGrpWiseFrm2001C1.Under5Years,
Pop_RaceAndAgeGrpWiseFrm2001C1.5to9Years,
Pop_RaceAndAgeGrpWiseFrm2001C1.9to14Years...
Pop_RaceAndAgeGrpWiseFrm2001C1.85AndAbove
there are 33 counties in our state and have 33 different tables whose
structure looks same as the above one with
'Pop_RaceAndAgeGrpWiseTblC1.ctyDistrictID' being different for each county.
There is a 'ctyDistrictdata' table which stores the information relating to
the counties like its name, ID and region etc... After storing the census
data into all those different county tables year wise, everything looks fine.
We have the relationships as, the 'ctyDistrictID' field from all the 33
tables are linked to 'ctyDistrictdata' table onto the same ID(field).
But when a query is written to pull the 'Under5Years' data for a particular
race and for two specified years from 5 different counties(tables) by linking
them, the result has so many duplicates in it. But the expected result should
only have 2 tuples: first for year one and second for year two. The query
looks as follows:
SELECT DISTINCT Pop_RaceAndAgegrpwiseFrm2001C1.statsYear,
Pop_RaceAndAgegrpwiseFrm2001C1.RaceName,
Pop_RaceAndAgegrpwiseFrm2001C1.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C2.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C3.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C4.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C5.[under 5 years]
FROM Pop_RaceAndAgegrpwiseFrm2001C1, Pop_RaceAndAgegrpwiseFrm2001C2,
Pop_RaceAndAgegrpwiseFrm2001C3, Pop_RaceAndAgegrpwiseFrm2001C4,
Pop_RaceAndAgegrpwiseFrm2001C5
WHERE (Pop_RaceAndAgegrpwiseFrm2001C1.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C2.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C3.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C4.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C5.RaceName="White");
I know there should be something wrong in the query which is written above
or in the way table join is performed. It might be that the design of the
tables itself for storing the census data is in a bad shape. Even after
looking at things, nothing is working out good. Which way the above kind of
census data can be stored in a database with a better design. Please assist
me in this.
Thanks for any help or suggestions provided.
I need to store information regarding race wise population of
every county of my state year wise, which is nothing but census data. Here
the data is categorized basing on different age groups. After thinking about
a lot of options for storing this kind of data, came up with a table(s)
design as follows.
Pop_RaceAndAgeGrpWiseFrm2001C1 - this table stores data for county one. here
the ctyDistrictID is 1.
the fields are: Pop_RaceAndAgeGrpWiseFrm2001C1.EntryID,
Pop_RaceAndAgeGrpWiseFrm2001C1.ctyDistrictID,
Pop_RaceAndAgeGrpWiseFrm2001C1.RaceName,
Pop_RaceAndAgeGrpWiseFrm2001C1.statsYear,
Pop_RaceAndAgeGrpWiseFrm2001C1.Under5Years,
Pop_RaceAndAgeGrpWiseFrm2001C1.5to9Years,
Pop_RaceAndAgeGrpWiseFrm2001C1.9to14Years...
Pop_RaceAndAgeGrpWiseFrm2001C1.85AndAbove
there are 33 counties in our state and have 33 different tables whose
structure looks same as the above one with
'Pop_RaceAndAgeGrpWiseTblC1.ctyDistrictID' being different for each county.
There is a 'ctyDistrictdata' table which stores the information relating to
the counties like its name, ID and region etc... After storing the census
data into all those different county tables year wise, everything looks fine.
We have the relationships as, the 'ctyDistrictID' field from all the 33
tables are linked to 'ctyDistrictdata' table onto the same ID(field).
But when a query is written to pull the 'Under5Years' data for a particular
race and for two specified years from 5 different counties(tables) by linking
them, the result has so many duplicates in it. But the expected result should
only have 2 tuples: first for year one and second for year two. The query
looks as follows:
SELECT DISTINCT Pop_RaceAndAgegrpwiseFrm2001C1.statsYear,
Pop_RaceAndAgegrpwiseFrm2001C1.RaceName,
Pop_RaceAndAgegrpwiseFrm2001C1.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C2.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C3.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C4.[under 5 years],
Pop_RaceAndAgegrpwiseFrm2001C5.[under 5 years]
FROM Pop_RaceAndAgegrpwiseFrm2001C1, Pop_RaceAndAgegrpwiseFrm2001C2,
Pop_RaceAndAgegrpwiseFrm2001C3, Pop_RaceAndAgegrpwiseFrm2001C4,
Pop_RaceAndAgegrpwiseFrm2001C5
WHERE (Pop_RaceAndAgegrpwiseFrm2001C1.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C2.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C3.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C4.RaceName="White" And
Pop_RaceAndAgegrpwiseFrm2001C5.RaceName="White");
I know there should be something wrong in the query which is written above
or in the way table join is performed. It might be that the design of the
tables itself for storing the census data is in a bad shape. Even after
looking at things, nothing is working out good. Which way the above kind of
census data can be stored in a database with a better design. Please assist
me in this.
Thanks for any help or suggestions provided.