There is a lot of repeated SQL in the database module that is used only by the Analyzer. This varies only in a couple areas: the select statement and the Candidate vs BallotMeasure joins. See here, here, and here.
These should be consolidated into one function that creates the SQL to support the various areas where the query is used.