only way would be using 4 queries - 1 to determine a number for the 'class_name_X' column header, 2 crosstabs (one each for name and number) and a final one to join on schoolid
Qry1 would be something like
Code:
SELECT A.School_ID, A.Class_Name, count(B.Class_Name) as ClassNo
FROM tblSchools A INNER JOIN tblSchools B ON A.school_ID=B.school_ID
WHERE B.Class_Name<=A.Class_Name
Qry2 would be something like
Code:
TRANSFORM First(A.Class_Name) AS [FirstOfClass_Name]
SELECT SchoolID
FROM tblSchools A INNER JOIN Qry1 B ON A.School_ID=B.School_ID AND A.Class_Name=B.Class_Name
GROUP BY A.School_ID
PIVOT B.ClassNo;
Qry3 would be similar, just substitute Class_nrOfStudent for Class_Name
Qry4
I'll leave to you but join qry2 to queries 3 and 4 on school_id. The reason I'm leaving it is because you'll need to cater for things like different schools having different numbers of classes