| From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
|---|---|
| To: | George Handin <postgresql(at)dafunks(dot)com>, pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Query to return modified results at runtime? |
| Date: | 2006-06-08 04:32:36 |
| Message-ID: | 20060608043236.96435.qmail@web31810.mail.mud.yahoo.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
> 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | George Handin | 2006-06-08 15:50:14 | Concat two fields into one at runtime |
| Previous Message | Richard Broersma Jr | 2006-06-08 01:03:21 | Re: How To Exclude True Values |