couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gabor Ratky <rg...@rgabostyle.com>
Subject Re: how to sum values of a view in a date range?
Date Thu, 09 Jun 2011 16:38:44 GMT
GET db/_design/power/_view/watt?group_level=4&startkey[2011,3]&endkey=[2011,3,{}]

group_level=4 means [year, month, day, hour], which is exactly what you need.

On Thursday, June 9, 2011 at 6:36 PM, Fabio Di Bernardini wrote:

> I need to make a chart with hourly sum of values restricted to March. So I
> don't need one number with the sum of whole March month.
> 
> 
> 2011/6/9 David Hardtke <david@cloudant.com (mailto:david@cloudant.com)>
> 
> > Hi Fabio,
> > 
> > This should work. You can use the _sum builtin as reduce:
> > 
> > "reduce":"_sum"
> > 
> > You then need to query your view with the proper group level and a startkey
> > and endkey:
> > 
> > GET
> > db/_design/power/_view/watt?group_level=2&startkey=[2011,3]&endkey=[2011,4]&inclusive_end=false
> > 
> > That gives you the sum for the month of March.
> > 
> > 
> > 
> > 
> > On 06/09/11 09:06, Fabio Di Bernardini wrote:
> > 
> > > Il 09/06/2011 17:18, Fabio Di Bernardini ha scritto:
> > > 
> > > > If I have a map function emitting a timestamp as key ad a number as
> > > > document, how to get sum of values selecting a date range?
> > > 
> > > More datails here:
> > > 
> > > http://stackoverflow.com/questions/6294794/how-to-sum-values-of-a-view-in-a-date-range-using-couchdb


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message