zoukankan      html  css  js  c++  java
  • mysql null值的特殊处理

    实例

    尝试以下实例:

    root@host# mysql -u root -p password;
    Enter password:*******
    mysql> use RUNOOB;
    Database changed
    mysql> create table tcount_tbl
        -> (
        -> runoob_author varchar(40) NOT NULL,
        -> runoob_count  INT
        -> );
    Query OK, 0 rows affected (0.05 sec)
    mysql> INSERT INTO tcount_tbl
        -> (runoob_author, runoob_count) values ('mahran', 20);
    mysql> INSERT INTO tcount_tbl
        -> (runoob_author, runoob_count) values ('mahnaz', NULL);
    mysql> INSERT INTO tcount_tbl
        -> (runoob_author, runoob_count) values ('Jen', NULL);
    mysql> INSERT INTO tcount_tbl
        -> (runoob_author, runoob_count) values ('Gill', 20);
    
    mysql> SELECT * from tcount_tbl;
    +-----------------+----------------+
    | runoob_author | runoob_count |
    +-----------------+----------------+
    | mahran          |             20 |
    | mahnaz          |           NULL |
    | Jen             |           NULL |
    | Gill            |             20 |
    +-----------------+----------------+
    4 rows in set (0.00 sec)
    
    mysql>

    以下实例中你可以看到 = 和 != 运算符是不起作用的:

    mysql> SELECT * FROM tcount_tbl WHERE runoob_count = NULL;
    Empty set (0.00 sec)
    mysql> SELECT * FROM tcount_tbl WHERE runoob_count != NULL;
    Empty set (0.01 sec)

    实例

    查找数据表中 runoob_count 列是否为 NULL,必须使用IS NULL和IS NOT NULL,如下实例:

    mysql> SELECT * FROM tcount_tbl 
        -> WHERE runoob_count IS NULL;
    +-----------------+----------------+
    | runoob_author | runoob_count |
    +-----------------+----------------+
    | mahnaz          |           NULL |
    | Jen             |           NULL |
    +-----------------+----------------+
    2 rows in set (0.00 sec)
    mysql> SELECT * from tcount_tbl 
        -> WHERE runoob_count IS NOT NULL;
    +-----------------+----------------+
    | runoob_author | runoob_count |
    +-----------------+----------------+
    | mahran          |             20 |
    | Gill            |             20 |
    +-----------------+----------------+
    2 rows in set (0.00 sec)
  • 相关阅读:
    京东商城招聘自动调价系统架构师 T4级别
    MVVM架构~Knockoutjs系列之对象与对象组合
    MVVM架构~Knockoutjs系列之text,value,attr,visible,with的数据绑定
    MVVM架构~mvc,mvp,mvvm大话开篇
    JS~delegate与live
    DDD~我们应该知道的Model,DomainModel和ViewModel
    uva-11111 Generalized Matrioshkas
    盒子模型(非常形象)
    SQL Server提高并发查询效率
    uva-11234 Expressions
  • 原文地址:https://www.cnblogs.com/panxuejun/p/6222656.html
Copyright © 2011-2022 走看看