No probado porque no proporcionó datos de prueba (de la tabla AC_XXXX
):
(utilizando la cláusula PIVOT de Oracle 11)
select *
from ( select emp_id, seq_nr, name
from ac_xxxx
where emp_id = '874830' )
pivot ( max(name) for seq_nr in (3 as seq3name, 4 as seq4name, 21 as seq21name,
22 as seq22name, 23 as seq23name, 24 as seq24name, 25 as seq25name)
)
;
Para Oracle 10 o anterior, la pivotación se realizaba "a mano", así:
select max(emp_id) as emp_id, -- Corrected based on comment from OP
max(case when seq_nr = 3 then name end) as seq3name,
max(case when seq_nr = 4 then name end) as seq4name,
-- etc. (similar expressions for the other seq_nr)
from ac_xxxx
where emp_id = '874830'
;
O, emp_id
no necesita estar dentro de max()
si agregamos group by emp_id
- que luego funcionará incluso sin la cláusula WHERE, para una pregunta diferente pero relacionada.