I have a database with student information and school classes. Then I try to query a result set showing key performance indicators for the different student subgroups we have at school. A very crude example of the end result:
Example of the table I'm trying to create
Please note that student groups overlap.
One and the same pupil may be included in Whole Year, Femalesand Non FSMetc .:

Now I have achieved this. I used aggregated functions and a GROUP BY clause for each subgroup, and then combined these queries with UNION ALL to create a table. A striking example of my code would be:
SELECT 'Whole Year' AS [Group], COUNT(student.name) AS [Total No. of Students]
UNION ALL
SELECT student.gender AS [Group], COUNT(student.name) AS [Total No. of Students]
GROUP BY student.gender
UNION ALL
SELECT student.fsm AS [Group], COUNT(student.name) AS [Total No. of Students]
GROUP BY student.fsm
, . HUGE, .
, , , , , - , .