Re: sum but not grouped by?

From: Henry Ortega <juandelacruz(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: sum but not grouped by?
Date: 2005-08-05 17:53:14
Message-ID: 2bffcc3305080510535e3c81ef@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Is it possible at all to do this without any joins
or subselect?

On 8/5/05, Mischa Sandberg <mischa(dot)sandberg(at)telus(dot)net> wrote:
> Quoting Henry Ortega <juandelacruz(at)gmail(dot)com>:
>
> > 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.
>
> You're really joining two sets:
>
> select FFDATA.id, FFDATA.date, FFDATA.hours, FFSUM.id_total
> from FFDATA
> join (select id, sum(hours) as id_total
> from FFDATA group by id
> ) as FFSUM using(id)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message PFC 2005-08-05 18:05:41 Re: sum but not grouped by?
Previous Message Mischa Sandberg 2005-08-05 16:47:55 Re: sum but not grouped by?