select 
to_char(min(time), 'YYYY-MM-DD HH24') as time,
avg(x_axis_angle) ,
avg(y_axis_angle) - ( ( (select avg(sensor_temperature) from zc where pn = 2008050087) - avg(sensor_temperature) ) * 0.0001 ),
avg(sensor_temperature) 
from zc
where pn = 2008050087 -- and time > now() - interval '24 hours'
group by to_char(time, 'YYYY-MM-DD HH24')
order by time asc 

