The problem
AND is evaluating a short circuit.
The value @reading:= 0is 0, which is incorrect.
0 and xalways 0, so MySQL does not evaluate x.
ORsuffers from the same problem: 1 OR xalways right.
This is a way to speed up the process by stopping as soon as the result is known.
@reading:= 0 XOR @prevdate:= @stepdate
, XOR .
1 XOR x , 0 XOR x.