select  vps1.personsnils_id, vps2.personsnils_id
-- 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 -- 463 886
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 and vps2.personsnils_insdt > vps21.personsnils_insdt limit 1) out2
where vps1.personsnils_insdt < vps2.personsnils_insdt
	limit 5
