sql server - Summing Row in SQL query for time range -
i'm trying group large amount of data smaller bundles.
currently code query follows
select [datetime] ,[kw] [power] datetime >= '2014-04-14 06:00:00' , datetime < '2014-04-21 06:00:00' order datetime
which gives me
datetime kw 4/14/2014 6:00:02.0 1947 4/14/2014 6:00:15.0 1946 4/14/2014 6:00:23.0 1947 4/14/2014 6:00:32.0 1011 4/14/2014 6:00:43.0 601 4/14/2014 6:00:52.0 585 4/14/2014 6:01:02.0 582 4/14/2014 6:01:12.0 580 4/14/2014 6:01:21.0 579 4/14/2014 6:01:32.0 579 4/14/2014 6:01:44.0 578 4/14/2014 6:01:53.0 578 4/14/2014 6:02:01.0 577 4/14/2014 6:02:12.0 577 4/14/2014 6:02:22.0 577 4/14/2014 6:02:32.0 576 4/14/2014 6:02:42.0 578 4/14/2014 6:02:52.0 577 4/14/2014 6:03:02.0 577 4/14/2014 6:03:12.0 577 4/14/2014 6:03:22.0 578 . . . . 4/21/2014 5:59:55.0 11
now there reading every 10 seconds substation. want group data hourly readings.
thus 00:00-01:00 = sum([kw]] datetime >= '^date^ 00:00:00' , datetime < '^date^ 01:00:00'
i've tried using convert change datetime date , time field , add time fields no success.
can please assist me, i'm not sure right way of doing this. thanks
added
ok spilt between datetime working nicely, if add sum([kw]) function sql gives error. , if include of group functions nags.
below works, still need sum kw per grouping of hours.
i've tried using group hour
, group datepart(hour,[datetime])
both didn't work.
select datepart(hour,[datetime]) hour ,datepart(day,[datetime]) day ,datepart(month,[datetime]) month ,([kvareal]) ,([kvar]) ,([kw]) [power].[dbo].[it10t_pac3200] datetime >= '2014-04-14 06:00:00' , datetime < '2014-04-21 06:00:00' order datetime
the function convert(varchar(13), getdate(), 120)
displays 2014-06-03 16
. can use group hour:
select convert(varchar(13), [datetime], 120) dt , sum(kw) sumkwperhour power [datetime] >= '2014-04-14 06:00:00' , [datetime]< '2014-04-21 06:00:00' group convert(varchar(13), [datetime], 120) order dt
Comments
Post a Comment