Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C2B69634705 for ; Wed, 2 Jun 2010 13:55:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 98413-06-2 for ; Wed, 2 Jun 2010 16:55:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 7CBE2633C43 for ; Wed, 2 Jun 2010 13:55:20 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id LJLCFXN2; Wed, 2 Jun 2010 17:55:18 +0100 Message-ID: <597755AB8EE8458F92F4B7C6588E5C03@marktestcr.marktest.pt> From: "Oliveiros" To: "Wes James" , References: Subject: Re: how to construct sql Date: Wed, 2 Jun 2010 17:55:18 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.229 tagged_above=-5 required=5 tests=BAYES_50=0.8, STOX_REPLY_TYPE=0.439, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: * X-Archive-Number: 201006/3 X-Sequence-Number: 34194 Hi, Have you already tried this out? select MAX(page_count_count) - MIN(page_count_count) from page_count group by page_count_pdate. Best, Oliveiros ----- Original Message ----- From: "Wes James" To: Sent: Wednesday, June 02, 2010 5:48 PM Subject: [SQL] how to construct sql >I am grabbing a printer total and putting it in a table. The > page_count is continuously increasing: > > page_count_count page_count_pdate > 10 2010-05-10 > 20 2010-05-10 > 40 2010-05-11 > 60 2010-05-11 > 80 2010-05-11 > 100 2010-05-12 > 120 2010-05-12 > ..... > > and so on. > > I can do: > > select sum(page_count_count) from page_count group by page_count_pdate. > > and get a total for a day. But this is not the total I want. I want > the total page count for the day. This would mean getting the first > page count of the day and then subtracting that from last page_count > for the day. For 2010-05-11 above it would be > > 80 - 40 = 40 total for the day. Is there a way to do this with sql? > > thx, > > -wes > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql