pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSum If
3+ messages / 2 participants
[nested] [flat]
* Sum If
@ 2006-02-23 17:46 Daniel Hernandez <breydan@excite.com>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Hernandez @ 2006-02-23 17:46 UTC (permalink / raw)
To: pgsql-sql
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!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Sum If
@ 2006-02-23 18:09 Jim Buttafuoco <jim@contactbda.com>
parent: Daniel Hernandez <breydan@excite.com>
0 siblings, 0 replies; 3+ messages in thread
From: Jim Buttafuoco @ 2006-02-23 18:09 UTC (permalink / raw)
To: breydan@excite.com; 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@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 "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 -------
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Sum If
@ 2006-02-23 19:03 Daniel Hernandez <breydan@excite.com>
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Hernandez @ 2006-02-23 19:03 UTC (permalink / raw)
To: jim@contactbda.com; pgsql-sql
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_heregroup by ...
_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-02-23 19:03 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-02-23 17:46 Sum If Daniel Hernandez <breydan@excite.com>
2006-02-23 18:09 ` Jim Buttafuoco <jim@contactbda.com>
2006-02-23 19:03 Re: Sum If Daniel Hernandez <breydan@excite.com>
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