pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
distinct with sum
2+ messages / 2 participants
[nested] [flat]

* distinct with sum
@ 2006-07-09 08:33  mbobi@mac.com
  0 siblings, 1 reply; 2+ messages in thread

From: mbobi@mac.com @ 2006-07-09 08:33 UTC (permalink / raw)
  To: pgsql-sql

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

Thanks in advance for your help.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: distinct with sum
@ 2006-07-09 12:41  Hélder M. Vieira <hmv@mail.telepac.pt>
  parent: mbobi@mac.com
  0 siblings, 0 replies; 2+ messages in thread

From: Hélder M. Vieira @ 2006-07-09 12:41 UTC (permalink / raw)
  To: pgsql-sql

>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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-07-09 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-07-09 08:33 distinct with sum mbobi@mac.com
2006-07-09 12:41 ` Hélder M. Vieira <hmv@mail.telepac.pt>

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