pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Buttafuoco <jim@contactbda.com>
To: breydan@excite.com
To: pgsql-sql@postgresql.org
Subject: Re: Sum If
Date: Thu, 23 Feb 2006 13:09:33 -0500
Message-ID: <20060223180822.M55494@contactbda.com> (raw)
In-Reply-To: <20060223174644.073502F616@xprdmxin.myway.com>
References: <20060223174644.073502F616@xprdmxin.myway.com>


try 

select ...,sum(case when sales.itemname = 'some' then sales.count else 0 end) as "Sales Candies"
from your_table_here
group by ...



---------- Original Message -----------
From: "Daniel Hernandez" <breydan@excite.com>
To: pgsql-sql@postgresql.org
Sent: Thu, 23 Feb 2006 12:46:44 -0500 (EST)
Subject: [SQL] Sum If

> Hi Guys,   I'm new on this group, and I have a question, is there a way to do a &quot;sum if&quot; (kind of)
> ?What i want to do is the following.Select customers.custid, if (sales.itemname = 'candy', sum(sales.count)) 
> as &quot;Sales candies&quot;, if (sales.itemname = 'some', sum(sales.count)) as &quot;Sales Some&quot;from 
> ...join ...where .....group by customers.custid ...Thanks in advanced, and best regards,Daniel 
> Hernández.Tijuana, BC, México.&quot;More you learn, more you earn&quot;.
> 
> _______________________________________________
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
------- End of Original Message -------




view thread (3+ messages)  latest in thread

Message-ID: <20060223180822.M55494@contactbda.com>
Permalink:  ../20060223180822.M55494@contactbda.com/
Also on:    postgresql.org/message-id/20060223180822.M55494@contactbda.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: jim@contactbda.com, breydan@excite.com
  Subject: Re: Sum If
  In-Reply-To: <20060223180822.M55494@contactbda.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