I'm using SQL Server 2008 R2 and need to create new tables grouped in Time intervals.
The data is data from a stock market index. I have the data in 1 minute intervals, now i need them in 5,10,15,30,45,60...minute intervals. My primary key is the time stamp.
My question is: how to query the 1 minute data table to return data that is grouped by a specific time interval for example 5 minute intervals.
The query must return the Highest, Lowest, Last and First values in that particular group and most importantly also the last entry of the time-stamp in the group.
I'm very new to the SQL language and have tried numerous code found on the net, but i cant get to exactly return the desired results.
Data:
TimeStamp | Open | High | Low | Close
2012-02-17 15:15:0 | 102 | 110 |100 |105
2012-02-17 15:16:0 |106 |112 |105 |107
2012-02-17 15:17:0 | 106 |110 |98 |105
2012-02-17 15:18:0 |105 |109 |104 |106
2012-02-17 15:19:0 |107 |112 |107 |112
2012-02-17 15:20:0 |115 |125 |115 |124
Desired Query Result (5 minutes):
Timestamp |Open|High|Low|Close
2012-02-15:19:0 |102 |125 |98 |124
2012-02-15:24:0 |115.|....|...|...
2012-02-15:29:0 |....|....|...|...