Given the tables below, what is the best approach to (in both server-flavors):
Group all rows within a minute/hour/day and get the maximum column ‘CounterC’ ?
Example: Between ‘now’ and ‘now’ – 1 day, get Max(CounterC) for each hour.
Example2: Between ‘now’ and ‘now’ – 30 days, get Max(CounterC) for each day.
Obviously the rows have to be grouped, but how?
MS SQL
CREATE TABLE [dbo].[DE0000000D102D1D](
[index] [bigint] IDENTITY(1,1) NOT NULL,
[TimeStamp] [datetime] NOT NULL,
[CounterA] [bigint] NOT NULL,
[CounterB] [bigint] NOT NULL,
[CounterC] [bigint] NOT NULL,
[CounterD] [bigint] NOT NULL,
)
MySQL
CREATE TABLE `de0000000d102d1d` (
`index` bigint(20) NOT NULL AUTO_INCREMENT,
`TimeStamp` datetime NOT NULL,
`CounterA` bigint(20) NOT NULL,
`CounterB` bigint(20) NOT NULL,
`CounterC` bigint(20) NOT NULL,
`CounterD` bigint(20) NOT NULL,
PRIMARY KEY (`index`)
)
Some example data:
index TimeStamp CounterA CounterB CounterC CounterD
----- ----------------------- -------- -------- --------- --------
1 2011-03-07 14:25:32.000 0 1 347406352 916
2 2011-03-07 14:26:32.000 0 1 347407169 916
3 2011-03-07 14:27:32.000 0 1 347407978 916
4 2011-03-07 14:28:31.000 0 1 347408617 916
5 2011-03-07 14:29:31.000 0 1 347409087 916
6 2011-03-07 14:30:30.000 0 1 347409557 916
7 2011-03-07 14:31:09.000 0 1 347409845 916
Thanks in advance!
Edit: It is actually Max(CounterC) I want for each interval, not the sum.
For SQL Server