Skip to content
Advertisement

How to Compare COUNT of Groups in Percentage in SQL?

I really new to SQL, currently learning PostgreSQL.

Suppose I have the following schema:

class(class_id, school_name), primary key: (class_id)

enroll(student_id, class_id), primary key: (student_id, class_id)

I want to find the class_id where the class’ sum of enrolled student is at least 10% higher than average.

I know that I can find sum of enrollment for any class by

But how do I compare one to the other in percentage?

Advertisement

Answer

here’s your query, you can use avg() and having clause

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement