News for hackers. Stuff that matters.
Re:SQL NULLs Are Weird by rawgabbit on Friday January 10, 2025 @08:21PM (#42662411)
Suppose you have table with two columns to represent a classroom’s exam scores. It has the columns student_id (varchar) and score (int).

If a student is sick and has not taken the exam, yes you could enter -99 to represent they did not take the test. But if you want to find the class average, you would have to do something like this:

select average(case when score =-99 then null else score end) as class_avg from …

Or you could have entered null to begin with.

There are no comments on this comment yet.