G
G
gowwa1232020-11-04 18:24:14
PostgreSQL
gowwa123, 2020-11-04 18:24:14

How to find the average value?

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

I need to find the average value for the subject column, I was thinking of doing this:
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

But it did not work out very well to cast the character varying type to int
spoiler
5fa2c60c26cf4082808557.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question