Vector Data and SQL Querying

Sep 3, 2013 • Jonah Duckles

Novice question

Which of the following is/are valid closed vector polygon(s)?

a) ( (1,1), (2,2), (2,3) )
b) ( (1,1), (2,2), (2,3), (1,1) )
c) ( (1,1), (2,2), (2,3), (0,0) )
d) ( (1,1), (2,2), (2,6), (1,1) )
e) a and c
f) b and d

Expert question

You’re working on a project at a new employer, you’re seeing a problem where your group by sums from your GIS census data aren’t rolling up correctly in a query written by the previous employee. Some counties are reporting multiple times when you run your query.

The query you’ve inherited is:

select county_fips, sum(population), sum(college_grads) from census_data group by tractid, county_fips;

The table might look like:

featureid   tractid     county_fips  state_fips  population  college_grads
----------  ----------  -----------  ----------  ----------  -------------
1           1           001          40          2000        200
2           20          002          40          5000        60
3           20          002          40          13000       900
3           22          002          40          15342       73

What is the correct query to sum the two variables population and college_grads for each county_fips?

a) select county_fips, average(population), average(college_grads) from census_data group by tractid, county_fips;
b) select county_fips, total(population), total(college_grads) from census_data group by tractid, county_fips;
c) select county_fips, sum(population), sum(college_grads) from census_data group by county_fips;
d) select tractid, sum(population), sum(college_grads) from census_data group by tractid;