Sum If
Sum If
От:
"Daniel Hernandez" <breydan@excite.com>
Дата:
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!
Re: Sum If
От:
"Jim Buttafuoco" <jim@contactbda.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" 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 -------
Re: Sum If
От:
"Daniel Hernandez" <breydan@excite.com>
Дата:
Hi Jim,
�� Thanks for the tip, It worked!!!!!
Thanks a lot!!!
Daniel Hern�ndez.
Tijuana, BC, M�xico.
"More you learn, more you earn".try
select ...,sum(case when sales.itemname = 'some' then sales.count else 0 end) as "Sales Candies"
from your_table_here
group by ...
Join Excite! - http://www.excite.com
The most personalized portal on the Web!