SQL to convert list of numbers into table format
create table t (d number);
insert into t
select level
from dual
connect by level <=25;
commit;
select C1, C2, C3, C4, C5
from (
select d,ceil(d/5) r, row_number() over(partition by ceil(d/5) order by d) c
from t)
pivot ( max(d) for c in (1 c1,2 c2,3 c3,4 c4,5 c5))
order by 1;
select C1, C2, C3, C4, C5
from (
select d,ceil(d/5) r, row_number() over(partition by ceil(d/5) order by d) c
from t)
pivot ( max(d) for d in (1 c1,2 c2,3 c3,4 c4,5 c5))
order by 1;
select max(case when mod(d,5)=1 then d end) c1,
max(case when mod(d,5)=2 then d end) c2,
max(case when mod(d,5)=3 then d end) c3,
max(case when mod(d,5)=4 then d end) c4,
max(case when mod(d,5)=0 then d end) c5
from t
group by ceil(d/5)
order by ceil(d/5);
create table t (d number);
insert into t
select level
from dual
connect by level <=25;
commit;
select C1, C2, C3, C4, C5
from (
select d,ceil(d/5) r, row_number() over(partition by ceil(d/5) order by d) c
from t)
pivot ( max(d) for c in (1 c1,2 c2,3 c3,4 c4,5 c5))
order by 1;
select C1, C2, C3, C4, C5
from (
select d,ceil(d/5) r, row_number() over(partition by ceil(d/5) order by d) c
from t)
pivot ( max(d) for d in (1 c1,2 c2,3 c3,4 c4,5 c5))
order by 1;
select max(case when mod(d,5)=1 then d end) c1,
max(case when mod(d,5)=2 then d end) c2,
max(case when mod(d,5)=3 then d end) c3,
max(case when mod(d,5)=4 then d end) c4,
max(case when mod(d,5)=0 then d end) c5
from t
group by ceil(d/5)
order by ceil(d/5);
No comments:
Post a Comment