0

I need to build a query which will give me employee id as columns. Since there can be any number of employees in a department, the number of columns is decided at runtime. The output should be as below. A,B,C,D etc. are employee id's

DEPT EMP1 EMP2 EMP3 EMP4 ... EMP(n)
===================================
10    A   B    C     D         E(n)
20    P   Q    R     
30    X   Y    
PTK
  • 307
  • 4
  • 19

1 Answers1

3

you need read about pivot operator

if number of employees is fixed read this Pivot and Unpivot

if number of emp is dynamic - read this thread Pivot Command, can the IN clause be dynamic rather than hard-coded values?

see this article Dynamic pivot in oracle sql

are
  • 2,535
  • 2
  • 22
  • 27
  • pivot needs a aggregate function. I don't want to aggregate any column but want to show the employee id's as column – PTK Jun 27 '17 at 11:16