Partitioning SQL query by arbitrary number of rows

HAZE

New Member
I have a SQL table with periodic measurements. I'd like to be able to return some summary method (say SUM) over the value column, for an arbitrary number of rows at a time. So if I had\[code\]id | reading1 105 147 1011 1213 1814 16\[/code\]I could sum over 2 rows at a time, getting (24, 22, 34), or I could sum 3 rows at a time and get (34, 46), if that makes sense. Note that the ID might not be contiguous -- I just want to operate by row count, in sort order.In the real world, the identifier is a timestamp, but I figure that (maybe after applying a \[code\]unix_timestamp()\[/code\] call) anything that works for the simple case above should be applicable. If it matters, I'm trying to gracefully scale the number of results returned for a plot query -- maybe there's a smarter way to do this? I'd like the solution to be general, and not impose a particular storage mechanism/schema on the data.
 
Top