Frist, I am not to PI.
I would like to write a query in PIOLEDB that will average the first five hours of the day for the tag. I did this query and it worked. however, it seems it is too expensive and if I did it for more than one tag, I get "time-out"
cast(sub.date_only as datetime) Date, sub.tag , avg(sub.value)
time, value,tag, concat(format(day(time),'00'),'/', format(month(time),'00'), '/', format(year(time),'####')) Date_only
where (tag like 'sinusoid' )
and time between '01/1/2015' and '1/5/2015'
and hour(time) between 1 and 5
and timestep = '1h') sub
group by sub.Date_only, sub.tag