Created
July 8, 2019 11:36
-
-
Save mattandrews/7c4b45993b0070203477357839926fdc to your computer and use it in GitHub Desktop.
Get average votes for yes, month-by-month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select DATE_FORMAT(createdAt, "%Y-%m-01") AS month, count(choice) as votesTotal, | |
(SELECT count(choice) | |
FROM survey | |
WHERE choice = 'no' | |
AND YEAR(createdAt) = YEAR(month) AND MONTH(createdAt) = MONTH(month) | |
) AS numNoVotes, | |
(SELECT 100 - numNoVotes / count(choice) * 100) AS percentageVotedYes | |
from survey | |
GROUP BY DATE_FORMAT(createdAt, "%Y-%m-01") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment