mysql數(shù)據(jù)庫中is null語句的用法
注意在mysql中,0或 null意味著假而其它值意味著真。布爾運(yùn)算的默認(rèn)真值是1。
對(duì)null的特殊處理即是在前面的章節(jié)中,為了決定哪個(gè)動(dòng)物不再是活著的,使用death is not null而不使用death != null的原因。
在group by中,兩個(gè)null值視為相同。
執(zhí)行order by時(shí),如果運(yùn)行 order by ... asc,則null值出現(xiàn)在最前面,若運(yùn)行order by ... desc,則null值出現(xiàn)在最后面。
null操作的常見錯(cuò)誤是不能在定義為not null的列內(nèi)插入0或空字符串,但事實(shí)并非如此。在null表示"沒有數(shù)值"的地方有數(shù)值
。使用is [not] null則可以很容易地進(jìn)行測(cè)試
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'),
新聞熱點(diǎn)
疑難解答
圖片精選