How to Exract SQL minute data to houly data in C#?

Hi

I have a SQL table that has data filled with million records and the date is in minutes it looks like :-

RowDateTimeMeter 1Meter 2Meter 3
25/05/2006 02:49:001220450489
25/05/2006 02:50:001223470500
25/05/2006 02:51:001227490511
25/05/2006 02:52:001230510522
25/05/2006 02:53:001233.5530533
25/05/2006 02:54:001236.9550544
25/05/2006 02:55:001240.3570555
25/05/2006 02:56:001243.7590566

I want to make a C# code or SQL query to the above table and convert the data to houlry by summing Meter1,Meter 2 and Meter 3 to be the average. I want to import all the hourly data to a new table that will look like :-

RowDateTimeMeter 1Meter 2Meter 3
25/05/2006 03:00:009854.44160527.5
25/05/2006 04:00:008634.43710533
25/05/2006 05:00:007411.43240538.5

Your help will be highly appreciated.

[13009 byte] By [Sibusiso] at [2007-12-22]
# 1

Try this. I leave the part about figuring the time display out to you.

select sum(meter1), sum(meter2), sum(meter3)
from fc
group by
datepart(yy,rowdatetime),
datepart(mm,rowdatetime),
datepart(dd,rowdatetime),
datepart(hh,rowdatetime)

ZahirJ at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

Will this work for a million rows? Will it not be summing over all 1 million rows?

If this doesn't work, then perhaps you'd have to instead select all rows that fall within a certain hour, sum those, and then move on to the next hour until reaching your end date.

ShellShock at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
ShellShock wrote:

Will this work for a million rows? Will it not be summing over all 1 million rows?

If this doesn't work, then perhaps you'd have to instead select all rows that fall within a certain hour, sum those, and then move on to the next hour until reaching your end date.

I agree with ShellShock, thats what I need.

Your help will be highly apprecaited.

Sibusiso at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...
# 4

I got it, thanks guys. Here is the solution I used :-


Select DateAdd(Hour, DateDiff(Hour, 0, RowDateTime), 0) As RowDateTime,
Avg(Meter1) As Meter1,
Avg(Meter2) As Meter2,
Avg(Meter3) As Meter3
From TableName
Group By DateAdd(Hour, DateDiff(Hour, 0, RowDateTime), 0)

Sibusiso at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# General...