Re: sum(if command

From: "king" <king_pepper99(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: sum(if command
Date: 2002-09-16 12:11:24
Message-ID: MTjh9.66736$z91.2546877@bin3.nnrp.aus1.giganews.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Col,

I should have been more specific. I should have completed the query.

SELECT STYLENO, SUM(IF(RECORDTYPE='5', TOTALQTY,0)) AS 'ONHAND'
SUM(IF(RECORDTYPE='6', TOTALQTY,0)) AS 'ONORDER'
FROM WHOE314 WHERE SEASON='202' AND STYLENO NOT LIKE'S%'
GROUP BY SEASON, STYLENO

result:
STYLENO | ONHAND | ONORDER
===========================
41321 | 210 | 195
19219 | 101 | 98

What I need to be able to do is cross tabulate the information. like in the
above mysql sql statement. Will the "case" function in postgres allow this?

Thanks

"CoL" <col(at)mportal(dot)hu> wrote in message news:3D85BD61(dot)7080208(at)mportal(dot)hu(dot)(dot)(dot)
> mysql "case": http://www.mysql.com/doc/en/Control_flow_functions.html
> postgres "case":
> http://www.postgresql.org/idocs/index.php?functions-conditional.html
>
> C.
>
> king wrote:
> > Hi,
> >
> > Does posgres support the equivalent to the mysql sum(if command in a SQL
> > statement? I did not see reference to it in my readings.
> >
> > For example:
> > SELECT STYLENO, SUM(IF(RECORDTYPE='5', TOTALQTY,0)) AS 'ONHAND'
> > FROM WHOE314 WHERE SEASON='202' AND STYLENO NOT LIKE'S%'
> > GROUP BY SEASON, STYLENO
> >
> >
> > thanks
> >
> >
> >
> >
> >
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Wim 2002-09-16 12:37:09 Urgent problem: AllocSetFree: cannot find block containing chunk ...
Previous Message Mike Mascari 2002-09-16 11:47:25 C-language example of using/returning numeric