I have a small block of logical reasoning. I have a table (table1) organized this way, but would need to return the query as table2 just below. Can anyone help me?
What you are looking for is to turn rows into columns, which can be reached through PIVOT
I set an example for you to achieve your goal:
create table teste (
codigo number,
nome varchar2(50),
uso varchar2(10),
arquivo varchar2(50),
tipo varchar2(50)
);
insert into teste values (10, 'Joao', 'SIM', 'C:JOAO/REALT', 'REALT');
insert into teste values (10, 'Joao', 'SIM', 'C:JOAO/BOLET', 'BOLET');
insert into teste values (10, 'Joao', 'SIM', 'C:JOAO/CHAM', 'CHAM');
Final Query:
select * from teste
pivot (
max(arquivo)
for tipo in ('REALT' as REAT,
'CHAM' as CHAM,
'BOLET' as BOLET
));
SELECT PQ.CODIGO, PQ.NOME, PQ.USO,
DECODE(PA.TIPO, 'REALT', PA.ARQUIVO) AS REALT,
DECODE(PA.TIPO, 'BOLET', PA.ARQUIVO) AS BOLET,
DECODE(PA.TIPO, 'CHAM', PA.ARQUIVO) AS CHAM FROM PQ, PA;