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 |
|
arusu
Yak Posting Veteran
60 Posts |
Posted - 2010-09-28 : 17:02:45
|
| I have a table with a datetime and a result and i want to make a view that will show the hourly result. So one column with the datetime showing hourly and one column with a result |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2010-09-28 : 17:11:57
|
| Could you give an example with sample data of what you have and what you'd like to see?Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
arusu
Yak Posting Veteran
60 Posts |
Posted - 2010-09-28 : 17:34:16
|
| ok so i have date result09/30/2010 09:30 1109/30/2010 09:31 309/31/2010 08:30 409/30/2010 09:30 5so the view should show:date result09/30/2010 09:00 1409/31/2010 08:00 409/30/2010 09:00 5so basically it's showing hourly results and if there is more than one result in an hour, it's added up |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-09-28 : 17:46:32
|
| [code]select dateadd(hh,datediff(hh,0,MyDateTime),0) as MyHour, sum(result) as MyResultfrom MyTablegroup by dateadd(hh,datediff(hh,0,MyDateTime),0)order by dateadd(hh,datediff(hh,0,MyDateTime),0)[/code]Finding the Start of Time PeriodsThe following links have functions that will find the start of Century, Decade, Year, Quarter, Month, Week, Day, Hour, 30 Minutes, 20 Minutes, 15 Minutes, 10 Minutes , 5 Minutes , x number of Minutes ,Minute , or Second.Start of Time Period Functions:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64755Start of Week Function:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47307Date/Time Info and Script Linkshttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762CODO ERGO SUM |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-30 : 12:18:56
|
quote: Originally posted by arusu ok so i have date result09/30/2010 09:30 1109/30/2010 09:31 309/31/2010 08:30 409/30/2010 09:30 5so the view should show:date result09/30/2010 09:00 1409/31/2010 08:00 409/30/2010 09:00 5so basically it's showing hourly results and if there is more than one result in an hour, it's added up
seehttp://visakhm.blogspot.com/2010/02/aggregating-data-over-time-slots.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|