Skip to content
Advertisement

How do I get the total number of students who are only active

I have two tables that store data for students – the students table and student_session table

students table structure

JavaScript

student_session table structure

JavaScript

Now, I’ve been able to get the total number of students in a class using this query

JavaScript

However, there are some students who have been disabled for non-payment of school fees or those that have left the school permanently. The problem is since these students were only disabled and not deleted, the query still counts them to the active students.

Now, I want to exclude the disabled students from being counted.

Note – in the students table structure, the ‘is_active’ row stores data for if a student is active or disabled. ‘yes’ means a student is active, ‘no’ means a student has been disabled.

How do I go about this?

Advertisement

Answer

Or a little more succinctly, you can just use the mysql COUNT() function with AS:

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