Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
blake
Starting Member
29 Posts |
Posted - 2005-11-02 : 22:04:46
|
| I have a table with events logged to them and my client application is grabbing the number of events over a certain time period to graph them. The table looks like:create table events( event_id int not null references event_names(event_id), event_date datetime not null default CURRENT_TIMESTAMP)So I'd like to have a running count of the events over the last n minutes, where n can be 5, 60, 240, etc. That's easy to do but what I'd like is to group the results so that I always get 50 records returned.So if I'm requesting the count of events over the last 50 minutes, each record would represent the count of events which happened over a 1 minute time slice.Any pointers? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-04 : 05:17:16
|
| Post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
blake
Starting Member
29 Posts |
Posted - 2005-11-04 : 21:45:43
|
quote: Originally posted by madhivanan Post some sample data and the result you want
Sample data:event_id event_date-------- -----------------------1 2005-10-01 00:00:00.0122 2005-10-01 00:00:00.0383 2005-10-01 00:00:00.1524 2005-10-01 00:00:00.3495 2005-10-01 00:00:00.6856 2005-10-01 00:00:00.7237 2005-10-01 00:00:00.8918 2005-10-01 00:00:00.9549 2005-10-01 00:00:01.05610 2005-10-01 00:00:01.23011 2005-10-01 00:00:01.507...1011 2005-10-01 00:00:59.0191012 2005-10-01 00:00:59.2381013 2005-10-01 00:00:59.934 So let's say I want to plot 60 seconds worth of data. In order to do this, I'll need to take those 1013 records and slice them up such that I'm using n equal time slices, and for convenience let's assume that n=50.So I'll have 50 bars on a bar chart, and 1 minute divided by 50 means that each bar is effectively a grouping of 60/50 or 1.2 seconds.So the results for 50 slices over 60 seconds would look like:slice_number event_start_date count------------ ----------------------- -----1 2005-10-01 00:00:00.000 102 2005-10-01 00:00:01.200 63 2005-10-01 00:00:02.400 114 2005-10-01 00:00:03.600 9...50 2005-10-01 00:00:58.800 5 etc. Does that make sense?The number of slices should be a parameter, and the time range should also be a parameter. |
 |
|
|
|
|
|