Created
March 1, 2016 15:17
-
-
Save Ygreg/9dc96399d40c897101e0 to your computer and use it in GitHub Desktop.
This file contains 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
def date_and_count1(query, "month" = period, status) do | |
from s in query, select: | |
[fragment("ROUND(100.0 * SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) / COUNT(*), 2) AS share", ^status), | |
fragment("date_trunc(?, created_at) AS date_trunc_created_at", "month")], | |
group_by: fragment("date_trunc(?, created_at)", "month") | |
end | |
def date_and_count2(query, "month" = period, status) do | |
from s in query, select: | |
[fragment("ROUND(100.0 * SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) / COUNT(*), 2) AS share", ^status), | |
fragment("date_trunc(?, created_at) AS date_trunc_created_at", ^period)], | |
group_by: fragment("date_trunc(?, created_at)", ^period) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment