Skip to content
Advertisement

Fill in Missing Values in Query

Say we have this dataset: Two students are enrolled in two different courses and attendance is taken for each student. I am interested in finding the attendance_dates for the students for which either one of them or both of them missed the respective subject. For the subject and the attendance_dates the students did not show up return NULL. For example: Chris missed English class on 2/5/2021 and both Chris and Joseph missed Chemistry and English on 2/6/2021.

I am using postgreSQL!

What I have tried:

Result:

Requested:

Advertisement

Answer

I think you really want a flag on each day for each student and subject indicating whether or not the student attended.

Use cross join to create a row for all dates, subjects, and students. Then bring in an flag to indicate whether the student attended on that day:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement