I have the following table structure:
The registration table, indicates the type of client's contract, if is checked (1) it means that the client is directly related to the class table, if not (0), it means that the client is related to a group and the group is related to a class.
EDIT When the control is 1, the id_group on registration table is null, it means that the client don't belong to a group, and have individual classes.
What I need, is to get the following result:
Client_name | 54 classes | 3 with status 0 | 51 with status 1
Where the number of classes is the sum of (classes related directly to registration table (control 1) with classes related to the group table (control 0))
I have this schema working with multiple queries, I load every client, then I load his classes, and count the classes status, but it's taking too much of the server, I need this result in a single database query.
Is there a way to get this result?