Skip to content

Commit

Permalink
puma stats table definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jspeis committed Nov 30, 2016
1 parent 8ac12a5 commit 39f4ef1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sql/geo_stats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ ARRAY(SELECT neighbor from attrs.geo_neighbors where geo = a.id) as county_neigh
FROM attrs.geo_names a
WHERE id LIKE '05000US%'
)

-- puma stats
CREATE TABLE stats.puma AS (
select
(select max(year) from acs_1yr.yg) as year,
a.id as geo,
(SELECT pos
FROM
(SELECT geo, pop, rank()
OVER (PARTITION BY LEFT(geo, 3) ORDER BY pop DESC) AS pos FROM acs_1yr.yg
WHERE year = (select max(year) from acs_1yr.yg) and geo like '79500' ||SUBSTR(a.id, 6, 4) || '%') as tmp
WHERE geo = a.id) as puma_state_rank,

(SELECT count(1) FROM acs_1yr.yg WHERE year = (select max(year) from acs_1yr.yg) AND
geo like '79500' ||SUBSTR(a.id, 6, 4) || '%') as pumas_in_state,

ARRAY( SELECT geo_neighbors.neighbor
FROM attrs.geo_neighbors
WHERE geo_neighbors.geo = a.id::text) AS puma_neighbors
FROM attrs.geo_names a
WHERE id LIKE '79500US%'
)

0 comments on commit 39f4ef1

Please sign in to comment.