select subject, role
from tetrika.lessons as tl, tetrika.users as tu
where tu.role = 'tutor'
group by role, tutor_id, tu.id, subject
having tl.tutor_id = tu.id
Мне для колонки subject нужно найти среднее значение, я подумывал сделать так:
select (sum(subject) :: int / count(subject)) as subject_avg, subject, role
from tetrika.lessons as tl, tetrika.users as tu
where tu.role = 'tutor'
group by role, tutor_id, tu.id, subject
having tl.tutor_id = tu.id
Но привести тип character varying в int не очень получилось