Monday, October 6, 2014

SQL for flushing Inactive Voters



count | ballotcounted_1 | ballotcounted_2
------+-----------------+-----------------
  634 | 0               | 1
  506 | 0               | 0
  333 | 1               | 1
  211 | 0               |
  153 |                 |
   51 | 1               |
   22 | 1               | 0
    8 |                 | 1
    7 |                 | 0

We can filter 'lost' voters like this:

~14K inactive in Whatcom County
~8K inactive in 42nd LD
~2K marked inactive since Certification of Primary e.g '08/20/2014'

That filter gives us these targets listed by priority

  • 333 of that remaining ~2K who voted in both of the last General Elections.
  • 73 of that remaining ~2K who voted only in the last General Election.
  • 642 of that remaining ~2K who voted only in the General Election before last.
Political piece is here.




--Postgres 9.35

Select Count(*)
From voterdb100214 
Where statuscode = 'I' and 
Precinctid in (Select precincts42 from ld42) and
lastupdatedate > '08/20/2014';

-- gotta love ARRAY[]
drop view lostrecent;
create view lostrecent as
Select ARRAY[registrationnumber::text,LastName,FirstName,residenceaddress],precinctid,lastupdatedate,
(2014 - extract(year from Birthdate)) as Age,ballotcounted_1,ballotcounted_2
From voterdb100214 
Where 
Precinctid in (Select precincts42 from ld42) and
statuscode = 'I' and 
lastupdatedate > '08/20/2014'
Order By PrecinctID,Age;

Select Count(*),ballotcounted_1,ballotcounted_2
From lostrecent
Group BY ballotcounted_1,ballotcounted_2
Order BY Count DESC;

Select lostrecent.array,Age,precinctid from lostrecent
Where ballotcounted_1 = '1' and ballotcounted_2 = '1';

--export to spreadsheet
copy (Select lostrecent.array,Age,precinctid from lostrecent
Where ballotcounted_1 = '1' and ballotcounted_2 = '1') to 'C:\Politics\RecentlyLostTwiceGE.csv' CSV HEADER;

Select precinctid,Count(precinctid)
From voterdb100214 
Where statuscode = 'I' and 
Precinctid in (Select precincts42 from ld42) and
lastupdatedate > '08/20/2014'
Group By precinctid
Order By count DESC;

-- Tell me who they are...
Select ARRAY[registrationnumber::text,LastName,FirstName],precinctid,lastupdatedate,
(2014 - extract(year from Birthdate)) as Age
From voterdb100214 
Where 
Precinctid in (Select precincts42 from ld42) and
statuscode = 'I' and 
lastupdatedate > '08/20/2014'
Order By PrecinctID,Age;

No comments:

Post a Comment