If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Aggregation < than one hour

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-12-04, 11:11
spol spol is offline
Registered User
 
Join Date: Jun 2004
Posts: 12
Question Aggregation < than one hour

Hi all,
I've got a table structured as follow and it's often filled with with new data each minute. Is it possible with a single query to retrieve data aggregation groupped by 15 minutes and half an hour ?? I can use GROUP BY SUBSTR(date,1,13) to get hourly aggregation but I really don't know how to get it with a lesser time.

Table structure
CREATE TABLE `test` (
`date` datetime NOT NULL ,
`value` float NOT NULL
) TYPE=MyISAM;

Sample data
+---------------------+------+
| date | value |
+---------------------+------+
| 2004-11-01 00:01:00 | 2 |
| 2004-11-01 00:02:00 | 1 |
| 2004-11-01 00:03:00 | 6 |
.......
| 2004-11-01 00:13:00 | 5 |
| 2004-11-01 00:14:00 | 7 |
| 2004-11-01 00:15:00 | 7 |
| 2004-11-01 00:16:00 | 6 |
......
| 2004-11-01 00:30:00 | 4 |
| 2004-11-01 00:31:00 | 3 |
| 2004-11-01 00:32:00 | 3 |
+---------------------+------+

desired result
| 2004-11-01 00:15:00 | 89|
| 2004-11-01 00:30:00 | 76|
| 2004-11-01 00:45:00 | 67|
| 2004-11-01 01:00:00 | 27|

Thank you very much!
Paolo Saudin
Reply With Quote
  #2 (permalink)  
Old 11-12-04, 12:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
select from_unixtime(900*floor((unix_timestamp(`date`)+89 9)/900)) as quarterhour
, sum(`value`) as sumvalue
from `test`
group by quarterhour
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-13-04, 03:15
spol spol is offline
Registered User
 
Join Date: Jun 2004
Posts: 12
Smile

Thank you very much !
Regard,
Paolo Saudin
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On