sql - Group by statement to do average of time -
my existing database has data coming id, value , time. there 1 record coming every 3 seconds. want select
statement use these data , group them based on id , hrly basis show average of values in hr. how can use group by
achieve ?
this sample data:
id value date time 5 5/18/2015 10:27:22 9 5/18/2015 10:27:25 b 7 5/18/2015 10:27:22 b 8 5/18/2015 10:27:22
i have data coming in every 3 seconds. want aggregated based on every hr of day reflect avg values of id in hr. want output like
id -a , gives avg of 7 , @ 10 on 5/18/2015
this relatively simple group have 2 types of columns generally. grouped columns , aggregates. in case grouped columns have id,date, , hr(calculated [time]). have 1 aggregated column in case: average of value. check out code:
select id, [date], datepart(hour,[time]) hr, avg(value) avg_val yourtable group id,[date],datepart(hour,[time])
Comments
Post a Comment