Created
April 9, 2015 10:16
-
-
Save phocke/5a9467493cac45d7a1b3 to your computer and use it in GitHub Desktop.
Reports sql
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
## Ruby | |
@crawl.v2_reports.select { |r| !r.reported_at.nil? } | |
sort_by { |r| r.reported_at.to_i }. | |
reverse. | |
uniq { |r| r.v2_report_template_id } | |
## Sql | |
[Stack overflow answer](http://stackoverflow.com/a/7250594) | |
SELECT t.* | |
FROM | |
(SELECT reported_at, MAX(id) as id FROM v2_reports GROUP BY reported_at) a | |
INNER JOIN v2_reports t ON (t.id = a.id) | |
## Sequel? | |
@crawl.v2_reports_dataset | |
.exclude(reported_at: nil) | |
.order("reported_at ASC") | |
.group(:v2_report_template_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment