CREATE OR REPLACE VIEW public.vw_partner_list AS
 SELECT v.partner_id,
    v.name,
    v.surname,
    v.email,
    v.phone,
    v.country,
    v.zinzino_range,
    v.is_tutor,
    v.is_professor,
    v.is_superadmin,
    v.is_student,
    COALESCE(sc.student_count, 0) AS student_count
   FROM vw_user_identity_roles v
     LEFT JOIN ( SELECT student_profiles.tutor_id,
            count(*)::integer AS student_count
           FROM student_profiles
          WHERE student_profiles.status::text = 'ACTIVE'::text
          GROUP BY student_profiles.tutor_id) sc ON sc.tutor_id = v.partner_id;;
