Re: Sum If

From: "Jim Buttafuoco" <jim(at)contactbda(dot)com>
To: breydan(at)excite(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: Sum If
Date: 2006-02-23 18:09:33
Message-ID: 20060223180822.M55494@contactbda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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(at)excite(dot)com>
To: pgsql-sql(at)postgresql(dot)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 -------

In response to

  • Sum If at 2006-02-23 17:46:44 from Daniel Hernandez

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Hernandez 2006-02-23 19:03:03 Re: Sum If
Previous Message Daniel Hernandez 2006-02-23 17:46:44 Sum If