Created
March 18, 2013 23:32
-
-
Save xrl/5191990 to your computer and use it in GitHub Desktop.
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
@report = ActiveRecord::Base.connection.execute(%Q{ | |
SELECT events_with_objects.year_month | |
,events_with_objects.count | |
FROM ( | |
SELECT generate_series(min(datetime)::date | |
,max(datetime)::date | |
,interval '1 month')::date AS tag | |
FROM events | |
) s | |
LEFT JOIN (SELECT year_month | |
,count(year_month) | |
FROM events | |
INNER JOIN event_objects | |
ON events.id = event_objects.event_id | |
AND event_objects.object_class = 'Provider' | |
AND event_objects.object_id = #{Cached::Event.connection.quote current_user.provider.id} | |
AND events.event = 'view' | |
GROUP BY 1 | |
) events_with_objects | |
ON events_with_objects.year_month = to_char(s.tag,'YYYY/MM') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment