Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Q: how to turn row into column using sql ?
tedchyn_at_yahoo.com writes:
> sir,
>
> tab_1
> -----
> 100
> 200
>
> how do i use sql to get
>
> 100 200
> in a single statement if i am not using 8.1.5.
> thanks ted chyn
select sum(decode(rownum,1,col_1,0)),sum(decode(rownum,2,col_1,0)) from tab_1
Is one way. There are probably more efficient ways, note that this only works if you know how many rows there are in the source column. If you don't then you have to dynamically construct the sql. I don't know of any way of writing sql that can return varying numbers of columns.
This may not be the best way to solve your real problem though. You might want to state what you're trying to accomplish by doing this.
--
greg
Received on Thu Jan 13 2000 - 14:20:35 CST
![]() |
![]() |