Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Question - Transpose rows to columns

Re: SQL Question - Transpose rows to columns

From: Matthias Gresz <GreMa_at_t-online.de>
Date: 4 Dec 1998 07:32:32 GMT
Message-ID: <74836g$gek$2@news02.btx.dtag.de>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US