On Sep 30, 2010, at 11:44 PM, Jordan Dahlke wrote:

> Is there a good way to do this with Select and Group By statement?

For a given definition of "good" :P

create temporary table range as
select  0 as start, 24 as end union all
select  25 as start, 49 as end union all
select  50 as start, 74 as end union all
select  75 as start, max( value ) as end from measurement;



select      range.start || ' - ' || range.end as time,
            sum( coalesce( speed.value, 0 ) ) as speed,
            sum( coalesce( direction.value, 0 ) ) as direction,
            sum( coalesce( temp.value, 0 ) ) as temp
from        range

left join   measurement speed
on          speed.variable = 'Speed' 
and         speed.time between range.start and range.end

left join   measurement direction
on          direction.variable = 'Direction' 
and         direction.time between range.start and range.end

left join   measurement temp
on          temp.variable = 'Temp' 
and         temp.time between range.start and range.end

group by    range.start,
            range.end

order by    range.start


_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to