I've just realised this is not quite doing what I need it to do. In some cases I have AttendanceDates with no AttendanceCodes, in these cases I would need the query to not include that Dates/Sessions in the total:
StudentID ModuleID AttendanceDate AttendaceSession AttendanceCode
123456 1 02/02/2018 1 P
123456 1 02/02/2018 2 P
123456 1 02/02/2018 3 P
123456 1 02/02/2018 4 A
123456 1 09/02/2018 1 L
123456 1 09/02/2018 2 A
123456 1 09/02/2018 3
123456 1 09/02/2018 4
234567 1 02/02/2018 1 P
234567 1 02/02/2018 2 P
234567 1 02/02/2018 3 P
234567 1 02/02/2018 4 P
234567 1 09/02/2018 1 A
234567 1 09/02/2018 2 A
234567 1 09/02/2018 3
234567 1 09/02/2018 4
Student ID - 123456
TotalSessions - 6
SessionsAttended - 4
StudentID - 234567
TotalSessions - 6
SessionsAttended - 6
StudentID ModuleID AttendanceDate AttendaceSession AttendanceCode
123456 1 02/02/2018 1 P
123456 1 02/02/2018 2 P
123456 1 02/02/2018 3 P
123456 1 02/02/2018 4 A
123456 1 09/02/2018 1 L
123456 1 09/02/2018 2 A
123456 1 09/02/2018 3
123456 1 09/02/2018 4
234567 1 02/02/2018 1 P
234567 1 02/02/2018 2 P
234567 1 02/02/2018 3 P
234567 1 02/02/2018 4 P
234567 1 09/02/2018 1 A
234567 1 09/02/2018 2 A
234567 1 09/02/2018 3
234567 1 09/02/2018 4
Student ID - 123456
TotalSessions - 6
SessionsAttended - 4
StudentID - 234567
TotalSessions - 6
SessionsAttended - 6