'Calculating student attendance using SQL
Given the following table schemas, how would you figure out the overall attendance rate for each grade on 2018-03-12?
Table 1: student_attendance_log
| column name | Data Type | Description |
|---|---|---|
| date | string | date of log per student_id, format is 'yyyy-mm-dd' |
| student_id | integer | id of the student |
| attendance_status | string | Possible values are ['present', 'tardy', 'absent'] |
Table 2: student_demographic
| column name | Data Type | Description |
|---|---|---|
| student_id | integer | id of the student |
| grade_level | integer | will be a value between 0-12, which corresponds |
| date_of_birth | string | Student birth date, format is 'yyyy-mm-dd' |
is my solution below correct?
select grade_level,
sum(if(attendence_status = 'present', 1,0))/count(AD.student_id) as overall_attendance_rate
from student_demographic SD
join student_attendance_log SL
on SD.student_id = SL.student_id
and date='2018-03-12'
group by 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
