On 2015-10-01 18:01, Ricardo - Engsolutions wrote:
create temp table teste(chave int, letra char(1), valor int);
insert into teste(chave, letra, valor)
values (45101,'A',4),
(45101,'S',23),
(45102,'A',4),
(45103,'S',23),
(45104,'A',4),
(45105,'S',23),
(45105,'W',3),
(45106,'S',23),
(45107,'A',4),
(45108,'W',3),
(45108,'A',4);
select x.chave,
x.letra,
x.valor
from
(
select chave,
letra,
valor,
row_number() over(partition by chave order by chave, valor) AS
classificacao
from teste
) x
where x.classificacao = 1
order by x.chave;
drop table teste;
Obrigado Ricardo, funciona perfeito!
Vou guardar isto nas minhas notas,
row_number() over(partition by chave order by chave, valor) AS
classificacao
Muito bom!
Eloi
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral