Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 2434 invoked from network); 23 Nov 2008 05:10:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Nov 2008 05:10:37 -0000 Received: (qmail 44506 invoked by uid 500); 23 Nov 2008 05:10:45 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 44469 invoked by uid 500); 23 Nov 2008 05:10:45 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 44458 invoked by uid 99); 23 Nov 2008 05:10:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Nov 2008 21:10:45 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [64.22.68.8] (HELO assmule.apisnetworks.com) (64.22.68.8) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Nov 2008 05:09:20 +0000 Received: from [192.168.0.11] (206-248-172-247.dsl.teksavvy.com [206.248.172.247]) by assmule.apisnetworks.com (Postfix) with ESMTPSA id D04502745BF for ; Sun, 23 Nov 2008 00:09:34 -0500 (EST) Message-ID: <4928E58C.4070000@silencegreys.com> Date: Sun, 23 Nov 2008 00:09:32 -0500 From: Jedediah Smith User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: couchdb-user@incubator.apache.org Subject: Re: sums by date view References: <4928BDBE.5000801@silencegreys.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Jan Lehnardt wrote: > If you query `_view/viewname`, you get the total sum of all `doc.amount` > instances. > > If you are using [2008, 11, 22, 21, 01, 00] for the date you can do: > > - query `_view/viewname?group_level=1` to get all amounts per year > - query `_view/viewname?group_level=2` to get all amounts per months > - etc... This would only give you the net difference for the given time period, not the absolute balance in the account. To get the balance for date d you need "sum(doc.amount) where doc.date < d". A possible compromise would be to use group_level to find the balance per component and then add those together on the client. Example: balance(2008-11-22) = sum(-inf to 2007-) + sum(2008-01- to 2008-10-) + sum(2008-11-01 to 2008-11-22) Or is this what you meant? A less arbitrary grouping method could also be used like converting the date to a second count and grouping by individual bits. This doesn't quite meet my criteria but would at least make better use of view indexes, assuming they work like I imagine they do. If a view like the above existed and I updated an old transaction, there would only be one rereduce for each group level, right?