Using a table of student class attendance, write SQL to get each student's most recent class date. Is there another way? What if you need the second-to-last class date?
The question was asked in the interview stage. Reported follow-ups were another implementation and retrieving the second-to-last date.
student_id order.student_id, most_recent_class_date, and second_to_last_class_date.class_date. Treat repeated attendance records on the same date as one class date; return null when a second distinct date does not exist.| Column | Type | Description |
|---|---|---|
| attendance_idPK | INT | Unique attendance record identifier |
| student_id | INT | Identifier of the student |
| class_date | DATE | Date on which the student attended class |