How to optimize constant querying for a sum of many rows?
The concept you want is called a "materialized view". Normally, a view is fundamentally just a query prepared in advance, that you can reference like a table for convenience. A materialized view is at least partially stored in the database.

In SQL Server, this is done by creating an indexed view. This acts as an index tied to the table(s) in the view, and is updated when the underlying rows are updated, just like any other index. Note that the SQL Server Developer's Edition is free, and has very few limits on it.

Near as I can tell, neither MYSQL nor PostGreSQL provide this feature in this form.

With such a materialized view, you still have a potential for a performance issue. Since the index is updated every time the underlying rows are updated, if you're trying to tally up votes in real time, you may find that the view is constantly being modified. Between frequent SELECTs against the view, and constant INSERTs and/or UPDATES on the underlying tables, you may face blocking issues, a major problem if it prevents you from showing results, and an even worse problem if it prevents votes from being entered in the first place!

You may want to think about another option. Consider if you need a real-time tally, or if one that's been updated recently (say, within the last 5 minutes) would be sufficient. From what I've seen in election results in the US, that's the path they seem to take.