select true and null "tan",false and null "fan",true or null "ton",false or null "fon";
结果如下:

怎么理解呢?
很简单,把null当做介于true和false中间的值,也就是如果true=1,false=0,则null=1/2。
and 运算选择较小的值:
true=1 and null=1/2 ,则min(1,1/2) = 1/2 ,即 null
false=0 and null=1/2,则min(0,1/2) = 0,即 false
or 运算选择的较大的值:
true=1 or null=1/2,则max(1,1/2) = 1 ,即 true
false=0 or null=1/2,则max(0,1/2) = 1/2,即null

文章解释了如何在编程中将null视为逻辑运算中的中间值,and运算会选择较小的值(如null相当于0.5时,结果为0),or运算则选择较大的值(null相当于0.5时,结果为1)。

970

被折叠的 条评论
为什么被折叠?



