Hello! There is a schema database of debtors in subjects at the university. 
I am interested in the following sample:
For each group, select the total number of debtors and the number of debtors who have more than two debts. The main tables that participate in the request:
- Students (StudentId (PK), GroupNumber, RecordBookNumber (record number), FirstName, LastName, MiddleName)
- Subjects (SubjectId (PK), Name)
- StudentsSubjects (StudentsSubjectsId (PK), SubjectId (FK), TeacherId (FK), MarkId (FK), ControlTypeId (FK), ControlPeriod (FK), CuratorID (FK))
I am able to display some data separately.
The amount of debt in the group
select Students.GroupNumber as groupNum, Count(StudentsSubjects.StId) as Kol_dolgov from StudentsSubjects, Students where Students.RecordBookNumber = StudentsSubjects.StId group by Students.GroupNumber order by groupNum The number of debtors who have more than two debts
select t1.Grp, count(t1.Rbn) as Kol_dol_bol2 from (select Students.GroupNumber as Grp, Students.RecordBookNumber as Rbn, count(StudentsSubjects.SubjId) as Kol_dolg from Students,StudentsSubjects, Subjects</li> where Students.RecordBookNumber = StudentsSubjects.StId and Subjects.SubjectId = StudentsSubjects.SubjId group by Students.RecordBookNumber, Students.GroupNumber having count(StudentsSubjects.SubjId) > 2) as t1 group by t1.Grp The number of debtors in the group
select Students.GroupNumber as Grp, count(Students.RecordBookNumber) as Kol_dolgnikov from Students group by Students.GroupNumber order by 1 But I can not combine all this in one table. Could you suggest how to do this and is it even possible, given this DB schema.