NULLIF()
NULLIF(a, b) returns NULL if a = b, else a. NULLIF(marks, 0) turns 0 into NULL so AVG skips zeros if you want that. Opposite-ish of IFNULL.
Trap — NULLIF as a general ‘if’ — use IF/CASE.
On the example next to this theory: NULLIF(): create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Exam tip
NULLIF(marks, 0) → NULL when marks is 0.