Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Question - Transpose rows to columns
George Dimopoulos schrieb:
>
> Are you able to transpose rows to columns easily with a single sql
> statement?
>
> example
>
> select id, (select value from lab where code = 'HG' AND patient_id =
> l.patient_id(+)) HG,
> (select value from lab where code = 'CR' and patient_id =
> l.patient_id(+) CR
> from lab l
Think you want to do something like:
SELECT
l.patient_id ID, DECODE(l.code,'HG',value,NULL) HG, DECODE(l.code,'CR',value,NULL) CR, DECODE(l.code,<other>,value,NULL) <0ther> FROM lab l;
HTH
Matthias
--
Matthias.Gresz_at_Privat.Post.DE
Always log on the bright side of life.
http://www.stone-dead.asn.au/movies/life-of-brian/brian-31.htm
Received on Fri Dec 04 1998 - 01:32:32 CST