On Wed, Oct 6, 2010 at 11:15 PM, Hank wrote:
> Ok, I can see that.
>
Oh, I wasn't implying that mine was necessarily better - I didn't even think
of doing it that way. I suggested a benchmark because different fuctions
might have different execution speeds. Now actually thinking about this,
I've
Ok, I can see that. Here's a different approach that gets it down to
two function calls and some math.. and the DATE_FORMAT call might not
even be needed depending on the actual application.
select
DATE_FORMAT(start_time, "%Y-%m-%d %h:" ) as dhour,
10*(minute(start_time)%6) as dtime
Two people already who suggested a text-based approach vs. my numeric
approach.
Analysing, my method takes a single function call per record (to_unixtime);
Travis' takes 4 (concat, date_format, truncate, minute) and Hank's 3
(concate, left, date_format).
Someone feel like benchmarking ? :-D
On
Here's what I came up with:
select concat(left(DATE_FORMAT(start_time, "%Y-%m-%d %h:%i"
),15),"0") as time, count(*) from table group by time
-Hank
>>
>> How would one go about to construct a query that counts items within an
>> increment or span of time, let's say increments of 10 minutes?
>>
Maybe you could use something like the following to truncate your times to
10 minute increments before doing your GROUP BY and COUNT():
select concat(date_format(timestamp_col, '%Y-%m-%d %H:'),
truncate(minute(timestamp_col) / 10, 0), '0') from your_table;
-Travis
---
convert to unixtime, convert your interval to unixtime, creatively combine
with integer division to get a base number for each period, group by that
and count().
2010/10/6 Pascual Strømsnæs
> Hi!
>
> How would one go about to construct a query that counts items within an
> increment or span of t