I have a MySQL table with hundreds of thousands of entries in it.
I need to specify a date range and select all the entries between those two dates. I then need to break down the entries hour by hour and obtain a specific field.
Use Case: I would need an hour-to-hour breakdown of the entries from June 6 to June 12. So, on June 6th I would need an array of entries from 12am to 1am, 1am to 2am, 2am to 3am, etc.
Which is faster? (and why!):
Running 144 SQL queries to
SELECT device_id FROM entries WHERE updated_at >= sometime AND updated_at <= sometime+1.hour
where sometime is something like 12pm to 1pm, and then 1pm to 2pm, etc.Running 1 SQL query to
SELECT device_id FROM entries WHERE updated_at >= start_date AND updated_at <= end_date
to get all the entries within the entire time period, and then use ruby to group the entries down by hour.
If anyone has any resources on why ruby or MySQL might be faster for this type of stuff, it would be much appreciated. Would like to do some reading.