select -- vps1.*, vps2.*
 count(vps1.personsnils_id)
from v_personsnils vps1
cross join lateral (select vps11.personsnils_id as personsnils_id from v_personsnils vps11 where vps1.person_id = vps11.person_id and vps1.personsnils_snils <> vps11.personsnils_snils limit 1) out1
inner join v_personsnils vps2 ON vps1.personsnils_snils = vps2.personsnils_snils and vps1.person_id <> vps2.person_id -- 11 281 326
cross join lateral (select vps21.personsnils_id as personsnils_id from v_personsnils vps21 where vps2.person_id = vps21.person_id and vps2.personsnils_snils <> vps21.personsnils_snils limit 1) out2
where out1.personsnils_id IS NOT NULL
	AND out2.personsnils_id IS NOT NULL
