List:General Discussion« Previous MessageNext Message »
From:Aveek Misra Date:July 27 2010 10:54am
Subject:RE: query results group/summed by interval
View as plain text  
try this ...

 select 5 * floor(seconds/5) as start, 5 * floor(seconds/5) + 5 as end, sum(calls) from
calls group by 5 * floor(seconds/5);

This should give you an output of the type

+-------+------+------------+
| start | end  | sum(calls) |
+-------+------+------------+
|     0 |    5 |        387 |
|     5 |   10 |        225 |
|    10 |   15 |         74 |
+-------+------+------------+


Thanks
Aveek
________________________________________
From: Ghulam Mustafa [mustafa.pk@stripped]
Sent: Tuesday, July 27, 2010 3:53 PM
To: mysql@stripped
Subject: query results group/summed by interval

Hi everyone,

i have two columns (seconds, number of calls), i need to produce a
report which will show total number of calls in intervals (let'say 10
seconds interval), i know i can do this programmability in my script but
i was wondering if it's possible to accomplish this behavior within
mysql. for example i have following data.

+----------+---------------+
|  calls   | queue_seconds |
+----------+---------------+
|      250 |          0.00 |
|       28 |          1.00 |
|       30 |          2.00 |
|       56 |          3.00 |
|       23 |          4.00 |
|       31 |          5.00 |
|       33 |          6.00 |
|       50 |          7.00 |
|       49 |          8.00 |
|       62 |          9.00 |
|       74 |         10.00 |
...
... and so on...
...
+----------+---------------+

now result should look like this with a 5 seconds interval.

+----------+---------------+
| count(*) | queue_seconds |
+----------+---------------+
|      250 |          0.00 |
|      168 |          5.00 |
|      268 |         10.00 |
...
... and so on...
...
+----------+---------------+

i would really appreciate your help.

Best Regards.

--
Ghulam Mustafa

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=1

Thread
query results group/summed by intervalGhulam Mustafa27 Jul
  • RE: query results group/summed by intervalAveek Misra27 Jul
    • Re: query results group/summed by intervalNguyen Manh Cuong31 Jul
RE: query results group/summed by intervalMartin Gainty31 Jul
RE: query results group/summed by intervalMartin Gainty31 Jul
  • RE: query results group/summed by intervalnuno.tavares1 Aug
    • RE: query results group/summed by intervalTravis Ard2 Aug