Reputation: 8322
i have three fields in database day, hour, value
every hour value will be stored in the database.
now i would like to take every four hours average value. for one day i need to get 6 rows with each row consisting four hours average value.
could you please help me regarding this.
Its not correct right?
Upvotes: 0
Views: 1153
Reputation: 238058
select day
, (hour - 1) DIV 4 /* or: (h + 3) DIV 4 */
, avg(value)
from YourTable
group by
day
, (hour - 1) DIV 4
Upvotes: 2
Reputation: 125204
Exact the same as Andomar's just using the integer division operator:
select day
, hour div 4
, avg(value)
from YourTable
group by
day
, hour div 4
Upvotes: 0