pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hélder M. Vieira <hmv@mail.telepac.pt>
To: pgsql-sql@postgresql.org
Subject: Re: distinct with sum
Date: Sun, 9 Jul 2006 13:41:52 +0100
Message-ID: <000f01c6a355$0dbf8240$6200a8c0@hmv02> (raw)
References: <5644020.1152434024188.JavaMail.mbobi@mac.com>

>I need to list products from the table of ordered products with ordered 
>quantities. Each product should be there only once but quantity should be a 
>sum from all the same products from the table.
> I prepared some query but in quantity column I can see only amount from 
> one record. I need to have sum there.
>
> The query:
> select distinct on (id_prod) id_prod, id_unit, sum(quantity) as result 
> from products where determinant = false group by id_prod, id_unit




select id_prod, id_unit, sum(quantity) as result
from products
where determinant = false
group by id_prod, id_unit



Hélder M. Vieira





view thread (2+ messages)

Message-ID: <000f01c6a355$0dbf8240$6200a8c0@hmv02>
Permalink:  ../000f01c6a355$0dbf8240$6200a8c0@hmv02/
Also on:    postgresql.org/message-id/000f01c6a355$0dbf8240$6200a8c0@hmv02

 · 

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: hmv@mail.telepac.pt
  Subject: Re: distinct with sum
  In-Reply-To: <000f01c6a355$0dbf8240$6200a8c0@hmv02>

* 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