Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

selecionando a coluna1 superior com a coluna2 correspondente


mão única
select t1.* from
(select id,max(pid) as Maxpid
from yourtable
group by id) t2
join yourtable t1 on t2.id = t1.id
and t2.Maxpid = t1.pid