레포트를 출력할려고하늗네 레포트에 기능이 없어서 쿼리로 만들어서 뿌릴려고하는데요..
col1 col2
A 11
B 12
C 13
D 14
E 15
F 16
G 17
위의 로우데이터가 예시로 7개 정도 적었는데 실제로 100개정도있어요..
col1 col2 col3 col4
A 11 B 12
C 13 D 14
E 15 F 16
G 17
또는
col1 col2 col3 col4
A 11 E 15
B 12 F 16
C 13 G 17
D 14
위의 두개처럼 쿼리를 조작하여 만들수 있나요????
실제로는 하나의 로우 데이터인데 두번째꺼는 col1 에 30개로우까지 나오고 col3 에 30개 나오고 다시 col1아래로 30개 나오고...이런식으로...
한번도 해보질 않아서요...해보신분 누구 답변 좀 부탁드려요
Comment 1
-
minsouk
2015.08.29 22:55
use tempdb
go
if object_id('tblx') is not null
drop table tblx
go
create table tblx
(col1 varchar(10)
,col2 int
)
go
insert into tblx
values
('A',11)
,('B',12)
,('C',13)
,('D',14)
,('E',15)
,('F',16)
,('G',17)
go
select * from tblx
go
select
max(case modVal when 1 then col1 else null end) 이
, max(case modVal when 1 then col2 else null end) 름
, max(case modVal when 2 then col1 else null end) 은
, max(case modVal when 2 then col2 else null end) 알
, max(case modVal when 0 then col1 else null end) 아
, max(case modVal when 0 then col2 else null end) 서
from
(
select
row_number() over (order by (select 1)) rn
, row_number() over (order by (select 1)) % 3 modVal
, col1
, col2
from tblx
) a
group by rn - case modVal when 0 then 3 else modval end
go