X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4C1269DC99F for ; Thu, 23 Feb 2006 14:09:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37361-05 for ; Thu, 23 Feb 2006 14:09:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from amanda.contactbda.com (ipn36372-f65123.cidr.lightship.net [216.204.66.227]) by postgresql.org (Postfix) with ESMTP id C9D889DC9EB for ; Thu, 23 Feb 2006 14:09:38 -0400 (AST) Received: from amanda.contactbda.com (amanda.contactbda.com [192.168.1.2]) by amanda.contactbda.com (8.12.11/8.12.11/Debian-3) with ESMTP id k1NI9Xe9029077; Thu, 23 Feb 2006 13:09:33 -0500 From: "Jim Buttafuoco" To: breydan@excite.com, pgsql-sql@postgresql.org Reply-To: jim@contactbda.com Subject: Re: Sum If Date: Thu, 23 Feb 2006 13:09:33 -0500 Message-Id: <20060223180822.M55494@contactbda.com> In-Reply-To: <20060223174644.073502F616@xprdmxin.myway.com> References: <20060223174644.073502F616@xprdmxin.myway.com> X-Mailer: Open WebMail 2.41 20040926 X-OriginatingIP: 192.168.1.1 (jim) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.129 required=5 tests=[AWL=0.129] X-Spam-Score: 0.129 X-Spam-Level: X-Archive-Number: 200602/282 X-Sequence-Number: 24292 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" 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 "sum if" (kind of) > ?What i want to do is the following.Select customers.custid, if (sales.itemname = 'candy', sum(sales.count)) > as "Sales candies", if (sales.itemname = 'some', sum(sales.count)) as "Sales Some"from > ...join ...where .....group by customers.custid ...Thanks in advanced, and best regards,Daniel > Hernández.Tijuana, BC, México."More you learn, more you earn". > > _______________________________________________ > Join Excite! - http://www.excite.com > The most personalized portal on the Web! ------- End of Original Message -------