Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') FROM elections_details WHERE ElectionID='60' AND ContestTitle = 'R STATE\'S AT' at line 1 Whole query: SELECT CandidateName, PartyCode, SUM(TotalVotes), SUM(VotesGroup1), SUM(VotesGroup2), SUM(VotesGroup3), (SUM(TotalVotes)/) FROM elections_details WHERE ElectionID='60' AND ContestTitle = 'R STATE\'S ATTORNEY' AND PrecinctName = 'BARR' AND CandidateName != 'UNDER VOTES' AND CandidateName != 'OVER VOTES' AND CandidateName != 'Number of Precincts for Race' AND CandidateName != 'Number of Precincts Reporting' GROUP BY CandidateName ORDER BY PartyCode, SUM(TotalVotes) DESC