zoukankan      html  css  js  c++  java
  • MySQL基础之 逻辑运算符

    mysql的逻辑运算符有四个:与、或、非、异或

    我们平时在谈论的时候不考虑带有NULL的情况,今天我们就来考虑一下带有NULL值,他们的结果是怎么样的

    AND(&&)运算符

    mysql> select 5 AND 6,0 AND 7,0 AND NULL,3 AND NULL,9 AND 2,0 AND 12,0 AND NULL,14 AND NULL;
    +---------+---------+------------+------------+---------+----------+------------+-------------+
    | 5 AND 6 | 0 AND 7 | 0 AND NULL | 3 AND NULL | 9 AND 2 | 0 AND 12 | 0 AND NULL | 14 AND NULL |
    +---------+---------+------------+------------+---------+----------+------------+-------------+
    |       1 |       0 |          0 |       NULL |       1 |        0 |          0 |        NULL |
    +---------+---------+------------+------------+---------+----------+------------+-------------+
    1 row in set (0.00 sec)

    OR(||)运算符

    mysql> select 5 OR 6,0 OR 7,0 OR 0,3 OR NULL,9 || 2,0 || 12,0 || NULL,14 || NULL;
    +--------+--------+--------+-----------+--------+---------+-----------+------------+
    | 5 OR 6 | 0 OR 7 | 0 OR 0 | 3 OR NULL | 9 || 2 | 0 || 12 | 0 || NULL | 14 || NULL |
    +--------+--------+--------+-----------+--------+---------+-----------+------------+
    |      1 |      1 |      0 |         1 |      1 |       1 |      NULL |          1 |
    +--------+--------+--------+-----------+--------+---------+-----------+------------+
    1 row in set (0.01 sec)

    NOT( ! )运算符

    mysql> select  NOT 5,NOT 0,NOT NULL, NOT 3,NOT 0;
    +-------+-------+----------+-------+-------+
    | NOT 5 | NOT 0 | NOT NULL | NOT 3 | NOT 0 |
    +-------+-------+----------+-------+-------+
    |     0 |     1 |     NULL |     0 |     1 |
    +-------+-------+----------+-------+-------+
    1 row in set (0.00 sec)

    总结:通过上面的分析我发现:NULL值是处于0和1之间的某个值,他也表示一个值,只不过这个值是NULL值,而不是0。在进行计算的时候,1与NULL则结果为NULL。而0与NULL则结果为0。1或NULL则结果为1,0或NULL则结果为NULL;可见NULL值是介于0和1之间的值。另外非NULL既不是1也不是0,还是NULL。

  • 相关阅读:
    (转)C#特性详解
    PHP MSSQL数据操作PDO API
    DWR
    配置JAVA的环境变量
    关​于​h​i​b​e​r​n​a​t​e​中​双​向​外​键​关​联​o​n​e​-​t​o​-​o​n​e​的​p​r​o​p​e​r​t​y​-​r​e​f​=​的​问​题(转)
    Hibernate 二级缓存 总结整理(转)
    EhCache 分布式缓存/缓存集群(转)
    MySQL分区表(转)
    通用权限设计
    (转)关于Struts 2 拦截器参数丢失问题
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/9930167.html
Copyright © 2011-2022 走看看