부서명 이름
-------------
10 AA
10 BB
10 CC
20 DD
20 EE
인 테이블 있을 때
출력 방법을
부서명 이름
-------------
10 AA
BB
CC
20 DD
EE
이렇게 찍으려면 어떻게 plsql 오라클에서는
break on 부서명;
select 부서명, 이름 where 테이블명 order by 부서명;
이라고 쳤는데
ms sql은 어떤지 궁금합니다.
Comment 2
-
Terry
2015.03.25 23:27
-
Terry
2015.03.26 08:23
--작동이 안되는 쿼리였군요 -_-;;
--수정해서 다시 댓글답니다..
--쿼리시작
With tbl (부서명,이름) as
(
Select '10','aa' union all
Select '10','bb' union all
Select '10','cc' union all
Select '20','dd' union all
Select '20','ee')
,tbl2 (부서명,seq,이름) as
(
Select a.부서명
,row_number() over (partition by a.부서명 order by a.이름 asc)
,a.이름
From tbl as a
)
Select (
Case When a.seq = 1
Then a.부서명
Else ''
End
) As 부서명칭
,a.이름 As 이름
From tbl2 as a
Order By a.부서명 ASC
,a.이름 asc
--쿼리끝
--폰이라 들여쓰기 양해바랍니다
--쿼리시작
With tbl (부서명,이름) as
(
Select 10,aa union all
Select 10,bb union all
Select 10,cc union all
Select 20,dd union all
Select 20,ee
)
,tbl2 (부서명,seq,이름) as
(
Select a.부서명
,row_number() over (partition by a.부서명 order by a.이름 asc)
,a.이름
From tbl as a
)
Select (case when a.seq = 1 then a.부서명 else '' end) as 부서명
,a.이름
From tbl2 as a
Order by a.부서명 ASC
,a.이름 asc
--쿼리끝
후아..들여쓰기도 대충은 됐네요..