https://liaoxuefeng.com/books/sql/query/aggregation/

SELECT class_id, gender, COUNT(*) num FROM students GROUP BY class_id, gender