Re: Query to return modified results at runtime? - Mailing list pgsql-sql

From George Handin
Subject Re: Query to return modified results at runtime?
Date
Msg-id 44884752.7030303@dafunks.com
Whole thread Raw
In response to Re: Query to return modified results at runtime?  (Richard Broersma Jr <rabroersma@yahoo.com>)
Responses Re: Query to return modified results at runtime?
List pgsql-sql
Richard Broersma Jr wrote:
>> ID    Color
>> ---   -------
>> 1     Blue
>> 2     Red
>> 3     Green
>> 4     Orange
>>
>> How would I rewrite the query to return results where the colors are 
>> replaced by letters to give the following results?
>>
>> ID    Color
>> ---   -------
>> 1     A
>> 2     D
>> 3     B
>> 4     C
> 
> 
> http://www.postgresql.org/docs/8.1/interactive/functions-conditional.html
> 
> this is probably the easiest to implement but hard to mangage over time.  Another solution would
> be to create color_code table that is referenced by your test table.  Then when you can create a
> query as: select a.ID, b.code from test as a join color_code as b on a.color = b.color;
> 
> There are additional solutions to this also. But these two are probably the easiest.

Thanks!


pgsql-sql by date:

Previous
From: George Handin
Date:
Subject: Concat two fields into one at runtime
Next
From: Kenneth B Hill
Date:
Subject: Re: Query to return modified results at runtime?