From: | "Oliveiros d'Azevedo Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt> |
---|---|
To: | "JORGE MALDONADO" <jorgemal1960(at)gmail(dot)com>, <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Conditional expresion in query |
Date: | 2012-02-09 15:37:40 |
Message-ID: | 5690BD247AA54F9488E46A6E4B6DB4C9@marktestcr.marktest.pt |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Yes, it does.
Can't see why not.
Why do you ask that, Jorge?
Have you tried and it failed?
Best,
Oliveiros
----- Original Message -----
From: JORGE MALDONADO
To: pgsql-novice(at)postgresql(dot)org
Sent: Thursday, February 09, 2012 3:25 PM
Subject: [NOVICE] Conditional expresion in query
I have been reading about contidional expresions in a query and I have a question about the following example included in the documentation:
SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
FROM test;
I would like to make a few changes but I need to give a name (an alias) to the result of the CASE. Can an "AS" be added as shown below?
SELECT a, b,
CASE WHEN a=b THEN a
ELSE a || '-' || b
END AS ab
FROM test;
Respectfully,
Jorge Maldonado
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Wood | 2012-02-09 16:28:41 | Re: Two Tables That Share Data? |
Previous Message | Carlos Mennens | 2012-02-09 15:33:11 | Re: Two Tables That Share Data? |