Re: Query Output Formatting - Y/N Depending On Count

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: "Cameron B(dot) Prince" <cprince(at)rideware(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Query Output Formatting - Y/N Depending On Count
Date: 2003-05-23 20:09:47
Message-ID: Pine.LNX.4.33.0305231408001.3092-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You want case:

select a,
case
when a=0 then 'Y'
else 'N'
end
from test;

On Fri, 23 May 2003, Cameron B. Prince wrote:

> Hi,
>
> I need to output a Y or N depending on a count being greater than 0 or not.
> I think I've seen a co-worker at a pervious job do something like this, but
> I am unable to find any examples on the list or in the docs.
>
> Here's my query:
>
> SELECT a.col, COUNT(DISTINCT b.col) AS col_count
> FROM table1 a
> LEFT OUTER JOIN table2 b
> ON a.col=b.col
> GROUP BY a.col
>
> So what I'm looking for is col_count to contain a Y if the count is greater
> than 0, else an N.
>
> Anyone know how to do this?
>
> Thanks,
> Cameron
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ed L. 2003-05-23 22:57:53 Building 7.3.2 on HP-UX w/out zlib/readline
Previous Message Cameron B. Prince 2003-05-23 20:06:13 Query Output Formatting - Y/N Depending On Count