select top 10 p.Nombre, p.Apellidos, (SELECT COUNT(*) FROM Personas ps WHERE PS.ParentCode LIKE '%' + CONVERT(VARCHAR, p.id) + '-%' ) Total from personas p ORDER BY Total desc