pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Henry Ortega <juandelacruz@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: sum but not grouped by?
Date: Fri, 5 Aug 2005 13:53:14 -0400
Message-ID: <2bffcc3305080510535e3c81ef@mail.gmail.com> (raw)
In-Reply-To: <1123260475.42f3983bafe6d@webmail.telus.net>
References: <2bffcc33050805092862a01b93@mail.gmail.com>
	<1123260475.42f3983bafe6d@webmail.telus.net>

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



On 8/5/05, Mischa Sandberg <mischa.sandberg@telus.net> wrote:
> Quoting Henry Ortega <juandelacruz@gmail.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@postgresql.org so that your
>       message can get through to the mailing list cleanly
>



view thread (6+ messages)  latest in thread

Message-ID: <2bffcc3305080510535e3c81ef@mail.gmail.com>
Permalink:  ../2bffcc3305080510535e3c81ef@mail.gmail.com/
Also on:    postgresql.org/message-id/2bffcc3305080510535e3c81ef@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: juandelacruz@gmail.com
  Subject: Re: sum but not grouped by?
  In-Reply-To: <2bffcc3305080510535e3c81ef@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox