퇴근5분전

 

sqler 질문글..

http://www.sqler.com/942478#1

 

아래처럼 풀이해봤음.

 

/*
col1 | col2

 1       10

 2       20

 3       30

 4       40

*/


;with tb
as
(
 select 1 as col1, 10 as col2
 union
 select 2 as col1, 20 as col2
 union
 select 3 as col1, 30 as col2
 union
 select 4 as col1, 40 as col2
)

select case when col = 1 then tmp1.col1 else tmp2.col11 end as col1,
   case when col = 1 then tmp1.col2 else tmp2.col22 end as col2
from ( values( 1),( 2 ) ) as tab ( col )
left join
(
 select 1 as k, col1, col2
 from tb
) as tmp1
on   tab.col = tmp1.k
left join
(
 select 2 as k, count( col1 ) as col11, sum( col2 ) as col22
    from tb
) as tmp2
on tab.col = tmp2.k