Ver originalSELECT grupo,clase,cantINTO maximoDeCadaGrupoFROM tabla tWHERE EXISTS (SELECT top 2 indice FROM tabla WHERE t.grupo=grupo AND t.indice=indice ORDER BY indice)ORDER BY grupo