Hello,
Consider this table structure / data :
Column : Connexions DateRecorded
Row1 : 10 1/1/2007 11:12:45 pm
Row2 : 11 1/1/2007 11:17:12 pm
Row3 : 13 1/1/2007 11:17:59 pm
Row4 : 12 1/1/2007 11:25:11 pm
Row5 : 11 1/1/2007 11:26:13 pm
Row6 : 10 1/1/2007 11:28:52 pm
Row7 : 9 1/1/2007 11:28:59 pm
Row8 : 8 1/1/2007 11:41:00 pm
Row9 : 7 1/1/2007 11:47:15 pm
Based on that table, I want to retrieve all the data from 11:12 to 12h00 (the getDate() returns 12:00:00), group by minute to get this :
Column : Connexions DateRecorded
Row1 : 10 1/1/2007 11:12
Row2 : 10 1/1/2007 11:13
Row3 : 10 1/1/2007 11:14
Row4 : 10 1/1/2007 11:15
Row5 : 10 1/1/2007 11:16
Row6 : 13 1/1/2007 11:17
Row7 : 13 1/1/2007 11:18
Row8 : 13 1/1/2007 11:19
Row9 : 13 1/1/2007 11:20
Row10 : 13 1/1/2007 11:21
Row11 : 13 1/1/2007 11:22
Row12 : 13 1/1/2007 11:23
Row13 : 13 1/1/2007 11:24
Row14 : 12 1/1/2007 11:25
Row15 : 11 1/1/2007 11:26
Row16 : 11 1/1/2007 11:27
Row17 : 10 1/1/2007 11:28
Row18 : 10 1/1/2007 11:29
Row19 : 10 1/1/2007 11:30
Row20 : 10 1/1/2007 11:31
Row21 : 10 1/1/2007 11:32
Row22 : 10 1/1/2007 11:33
Row23 : 10 1/1/2007 11:34
Row24 : 10 1/1/2007 11:35
Row25 : 10 1/1/2007 11:36
Row26 : 10 1/1/2007 11:37
Row27 : 10 1/1/2007 11:38
Row28 : 10 1/1/2007 11:39
Row29 : 10 1/1/2007 11:40
Row30 : 8 1/1/2007 11:41
Row31 : 8 1/1/2007 11:42
Row32 : 8 1/1/2007 11:43
Row33 : 8 1/1/2007 11:44
Row34 : 8 1/1/2007 11:45
Row35 : 8 1/1/2007 11:46
Row36 : 7 1/1/2007 11:47
Please note that we do a MAX for grouping, so we keep the MAXIMUM value of the grouped records for the same minute. The complexity is to fill the record for each minute that is not on the table.
If it's not possible with a single SQL query, a stored proc is OK ;)
Thanks!
Start Free Trial