欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysql中is null語句的用法分享

 更新時間:2011年05月07日 22:00:30   作者:  
對null的特殊處理即是在前面的章節(jié)中,為了決定哪個動物不再是活著的,使用death is not null而不使用death != null的原 因

mysql數(shù)據(jù)庫中is null語句的用法

注意在mysql中,0或 null意味著假而其它值意味著真。布爾運(yùn)算的默認(rèn)真值是1。

對null的特殊處理即是在前面的章節(jié)中,為了決定哪個動物不再是活著的,使用death is not null而不使用death != null的原因。

在group by中,兩個null值視為相同。

執(zhí)行order by時,如果運(yùn)行 order by ... asc,則null值出現(xiàn)在最前面,若運(yùn)行order by ... desc,則null值出現(xiàn)在最后面。

null操作的常見錯誤是不能在定義為not null的列內(nèi)插入0或空字符串,但事實(shí)并非如此。在null表示"沒有數(shù)值"的地方有數(shù)值

。使用is [not] null則可以很容易地進(jìn)行測試


is null or = null


mysql>
mysql> create table topic(
    ->    topicid     smallint not null auto_increment primary key,
    ->    name        varchar(50) not null,
    ->    instock     smallint unsigned not null,
    ->    onorder     smallint unsigned not null,
    ->    reserved    smallint unsigned not null,
    ->    department  enum('classical', 'popular') not null,
    ->    category    varchar(20) not null,
    ->    rowupdate   timestamp not null
    -> );
query ok, 0 rows affected (0.02 sec)

mysql>
mysql>
mysql> insert into topic (name,          instock, onorder, reserved, department,   category) values
    ->                   ('java',          10,      5,       3,        'popular',    'rock'),
    ->                   ('css',    10,      5,       3,        'classical',  'opera'),
    ->                   ('c sharp',       17,      4,       1,        'popular',    'jazz'),
    ->                   ('c',             9,       4,       2,        'classical',  'dance'),
    ->                   ('c++',           24,      2,       5,        'classical',  'general'),
    ->                   ('perl',          16,      6,       8,        'classical',  'vocal'),
    ->                   ('python',        2,       25,      6,        'popular',    'blues'),
    ->                   ('php',           32,      3,       10,       'popular',    'jazz'),
    ->                   ('asp.net',       12,      15,      13,       'popular',    'country'),
    ->                   ('vb.net',        5,       20,      10,       'popular',    'new age'),
    ->                   ('vc.net',        24,      11,      14,       'popular',    'new age'),
    ->                   ('uml',           42,      17,      17,       'classical',  'general'),
    ->                   ('www.java2s.com',25,      44,      28,       'classical',  'dance'),
    ->                   ('oracle',        32,      15,      12,       'classical',  'general'),
    ->                   ('pl/sql',        20,      10,      5,        'classical',  'opera'),
    ->                   ('sql server',    23,      12,      8,        'classical',  'general');
query ok, 16 rows affected (0.00 sec)
records: 16  duplicates: 0  warnings: 0

mysql>
mysql> select * from topic;
+---------+----------------+---------+---------+----------+------------+----------+---------------------+
| topicid | name           | instock | onorder | reserved | department | category | rowupdate           |
+---------+----------------+---------+---------+----------+------------+----------+---------------------+
|       1 | java           |      10 |       5 |        3 | popular    | rock     | 2007-07-23 19:09:45 |
|       2 | javascript     |      10 |       5 |        3 | classical  | opera    | 2007-07-23 19:09:45 |
|       3 | c sharp        |      17 |       4 |        1 | popular    | jazz     | 2007-07-23 19:09:45 |
|       4 | c              |       9 |       4 |        2 | classical  | dance    | 2007-07-23 19:09:45 |
|       5 | c++            |      24 |       2 |        5 | classical  | general  | 2007-07-23 19:09:45 |
|       6 | perl           |      16 |       6 |        8 | classical  | vocal    | 2007-07-23 19:09:45 |
|       7 | python         |       2 |      25 |        6 | popular    | blues    | 2007-07-23 19:09:45 |
|       8 | php            |      32 |       3 |       10 | popular    | jazz     | 2007-07-23 19:09:45 |
|       9 | asp.net        |      12 |      15 |       13 | popular    | country  | 2007-07-23 19:09:45 |
|      10 | vb.net         |       5 |      20 |       10 | popular    | new age  | 2007-07-23 19:09:45 |
|      11 | vc.net         |      24 |      11 |       14 | popular    | new age  | 2007-07-23 19:09:45 |
|      12 | uml            |      42 |      17 |       17 | classical  | general  | 2007-07-23 19:09:45 |
|      13 | www.java2s.com |      25 |      44 |       28 | classical  | dance    | 2007-07-23 19:09:45 |
|      14 | oracle         |      32 |      15 |       12 | classical  | general  | 2007-07-23 19:09:45 |
|      15 | pl/sql         |      20 |      10 |        5 | classical  | opera    | 2007-07-23 19:09:45 |
|      16 | sql server     |      23 |      12 |        8 | classical  | general  | 2007-07-23 19:09:45 |
+---------+----------------+---------+---------+----------+------------+----------+---------------------+
16 rows in set (0.00 sec)

mysql>
mysql>
mysql> select name, department, category
    -> from topic
    -> where category is null
    -> order by name;
empty set (0.00 sec)

mysql>
mysql>
mysql>
mysql> select name, department, category
    -> from topic
    -> where category = null
    -> order by name;
empty set (0.00 sec)

mysql>
mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.00 sec)

 <=>null: null不等空
null意味著“沒有值”或www.3ppt.com“未知值”,且它被看作與眾不同的值。為了測試null,你不能使用算術(shù)比較 操作符例如=、<或!=
mysql>
mysql> select name, department, category
    -> from topic
    -> where category<=>null
    -> order by name;
empty set (0.00 sec)

mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.02 sec)

is not null


mysql> select name, department, category
    -> from topic
    -> where category is not null
    -> order by name;
+----------------+------------+----------+
| name           | department | category |
+----------------+------------+----------+
| asp.net        | popular    | country  |
| c              | classical  | dance    |
| c sharp        | popular    | jazz     |
| c++            | classical  | general  |
| java           | popular    | rock     |
| javascript     | classical  | opera    |
| oracle         | classical  | general  |
| perl           | classical  | vocal    |
| php            | popular    | jazz     |
| pl/sql         | classical  | opera    |
| python         | popular    | blues    |
| sql server     | classical  | general  |
| uml            | classical  | general  |
| vb.net         | popular    | new age  |
| vc.net         | popular    | new age  |
| www.java2s.com | classical  | dance    |
+----------------+------------+----------+
16 rows in set (0.00 sec)

mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.00 sec)

相關(guān)文章

  • MySQL語句整理及匯總介紹

    MySQL語句整理及匯總介紹

    今天小編就為大家分享一篇關(guān)于MySQL語句整理及匯總介紹,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • mysql中order by與group by的區(qū)別

    mysql中order by與group by的區(qū)別

    以下是對mysql中order by與group by的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過來參考下
    2013-07-07
  • MySQL 語句執(zhí)行順序舉例解析

    MySQL 語句執(zhí)行順序舉例解析

    這篇文章主要介紹了MySQL 語句執(zhí)行順序舉例解析,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值需要的小伙伴可以參考一下
    2022-06-06
  • MySQL數(shù)據(jù)入庫時特殊字符處理詳解

    MySQL數(shù)據(jù)入庫時特殊字符處理詳解

    本文是對MySQL數(shù)據(jù)入庫時特殊字符的處理進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2013-11-11
  • 一臺電腦(windows系統(tǒng))安裝兩個版本MYSQL方法步驟

    一臺電腦(windows系統(tǒng))安裝兩個版本MYSQL方法步驟

    由于新舊項(xiàng)目數(shù)據(jù)庫版本差距太大,編碼格式不同,引擎也不同,所以只好裝兩個數(shù)據(jù)庫,這篇文章主要給大家介紹了關(guān)于一臺電腦(windows系統(tǒng))安裝兩個版本MYSQL的方法步驟,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • Mysql中的sql優(yōu)化實(shí)踐詳解

    Mysql中的sql優(yōu)化實(shí)踐詳解

    這篇文章主要介紹了Mysql中的sql優(yōu)化實(shí)踐詳解,SQL優(yōu)化是指通過改進(jìn)SQL語句的編寫和查詢計(jì)劃的設(shè)計(jì)來提高數(shù)據(jù)庫查詢性能的過程,在優(yōu)化SQL時,可以采取一些措施來提升查詢性能,需要的朋友可以參考下
    2023-09-09
  • MySQL實(shí)現(xiàn)簡單的創(chuàng)建庫和創(chuàng)建表操作方法

    MySQL實(shí)現(xiàn)簡單的創(chuàng)建庫和創(chuàng)建表操作方法

    MySQL是最常用的數(shù)據(jù)庫,在數(shù)據(jù)庫操作中基本都是增刪改查操作,簡稱CRUD,這篇文章主要給大家介紹了關(guān)于MySQL實(shí)現(xiàn)簡單的創(chuàng)建庫和創(chuàng)建表操作方法的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • mysql installer community 8.0.16.0安裝配置圖文教程

    mysql installer community 8.0.16.0安裝配置圖文教程

    這篇文章主要為大家詳細(xì)介紹了mysql installer community 8.0.16.0安裝配置圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • 詳解MySQL分區(qū)表

    詳解MySQL分區(qū)表

    這篇文章主要介紹了MySQL分區(qū)表的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)mysql,感興趣的朋友可以了解下
    2020-08-08
  • MySQL中distinct與group by之間的性能進(jìn)行比較

    MySQL中distinct與group by之間的性能進(jìn)行比較

    這篇文章主要針對MySQL中distinct與group by之間的性能進(jìn)行比較,內(nèi)容比較詳細(xì),很直觀的能看出比較結(jié)果,感興趣的小伙伴們可以參考一下
    2015-11-11

最新評論