X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6699552DDA for ; Sun, 7 Aug 2005 11:53:08 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45059-01 for ; Sun, 7 Aug 2005 14:52:59 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by svr1.postgresql.org (Postfix) with ESMTP id A2FC852DE8 for ; Sun, 7 Aug 2005 11:52:58 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i22so874431wra for ; Sun, 07 Aug 2005 07:53:03 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:organization:user-agent:x-accept-language:mime-version:to:cc:subject:references:in-reply-to:content-type:from; b=LWI/OTPpO9usvJ176MUj0RWAR4P05O4W+iB9REWimrMdlZsK4gYeNcm5h0WUVqI4QJQdpAHHc+ILdnSjFdLHv2C+p90yK7hL+ZkzjaQQUGUUFu0a9Xfy1cnQcnje6b6OJq/F/mU8bj/HpuQ95s+zQPc2aQGQCjxKWyfF+giEkYE= Received: by 10.54.5.66 with SMTP id 66mr4145343wre; Sun, 07 Aug 2005 07:53:03 -0700 (PDT) Received: from ?217.201.223.202? ([217.201.223.202]) by mx.gmail.com with ESMTP id 29sm5183648wrl.2005.08.07.07.52.55; Sun, 07 Aug 2005 07:53:03 -0700 (PDT) Message-ID: <42F62031.9070700@students.cefriel.it> Date: Sun, 07 Aug 2005 16:52:33 +0200 Organization: nous s.r.l. User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: it, it-it, en-us, en MIME-Version: 1.0 To: Henry Ortega Cc: pgsql-sql@postgresql.org Subject: Re: sum but not grouped by? References: <2bffcc33050805092862a01b93@mail.gmail.com> In-Reply-To: <2bffcc33050805092862a01b93@mail.gmail.com> Content-Type: multipart/alternative; boundary="------------080705070807000604020504" From: Luca Rasconi Master X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.165 tagged_above=0 required=5 tests=HTML_50_60, HTML_MESSAGE, HTML_TITLE_EMPTY, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200508/86 X-Sequence-Number: 22314 This is a multi-part message in MIME format. --------------080705070807000604020504 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit let ff your table... try this: *select * a.id, a.date, a.hours, (*select *sum(b.hours) *from *ff as b *where *a.id = b.id *group *by b.id ) as a *from *ff as a; bye, Luca Henry Ortega ha scritto: >I have the ff data: > >id | date | hours >AAA 07-01-2005 3 >AAA 07-02-2005 4 >BBB 07-01-2005 6 >BBB 07-02-2005 2 >BBB 07-03-2005 7 > >Would it be possible to get the ff: > >id | date | hours | id_total >AAA 07-01-2005 3 7 >AAA 07-02-2005 4 7 >BBB 07-01-2005 6 15 >BBB 07-02-2005 2 15 >BBB 07-03-2005 7 15 > >So it's like SUM OF, but not Grouped By? Is this possible at all? >Thank you for any help. > >---------------------------(end of broadcast)--------------------------- >TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > > --------------080705070807000604020504 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit let ff your table...
try this:
select
    a.id,
    a.date,
    a.hours,
    (select sum(b.hours)
        from ff as b
        where a.id = b.id
        group by b.id
    ) as a
    from ff as a;

bye,
Luca

Henry Ortega ha scritto:
I have the ff data:

id      |     date         |      hours
AAA    07-01-2005           3
AAA    07-02-2005           4
BBB    07-01-2005           6
BBB    07-02-2005           2
BBB    07-03-2005           7

Would it be possible to get the ff:

id      |     date         |      hours   |   id_total
AAA    07-01-2005           3              7
AAA    07-02-2005           4              7
BBB    07-01-2005           6              15
BBB    07-02-2005           2              15
BBB    07-03-2005           7              15

So it's like SUM OF, but not Grouped By? Is this possible at all?
Thank you for any help.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
  

--------------080705070807000604020504--