You should read about aggregate functions. There are many places to read, but you can get a quick start by using the Stairway to T-SQL DML on this site[/url].
Your query would look something like this:
SELECT gender,
COUNT(DISTINCT student) total, --Use student as different students can share the name but not student id
year
FROM YourTable
GROUP BY gender, year
Try to read something about data normalization[/url] which might complicate things on the beginning, but you'll be grateful when things start to get serious.