MYSQL的一个奇怪语句

yinghuaxingfu 2003-08-19 10:30:40
注:online是表名
select count(*) as nums from online where username is not null
问题:is not null 这样的语法对吗?
请朋友指教
...全文
28 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujuntao 2003-08-20
  • 打赏
  • 举报
回复
where username is not null
username字段不为null
当然是对的了
因为大多数的数据库中,对null的判断,都是特出的,用这种方式,而不能用=null的
web_spider 2003-08-20
  • 打赏
  • 举报
回复
看看下面这两段关于null的经典描述
The NULL value means "no data" and is different from values such as 0 for numeric types or the empty string for string types.

The concept of the NULL value is a common source of confusion for newcomers to SQL, who
often think that NULL is the same thing as an empty string ''. This is not the case! For
example, the following statements are completely dierent:
mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ("");
Both statements insert a value into the phone column, but the rst inserts a NULL value
and the second inserts an empty string. The meaning of the rst can be regarded as \phone
number is not known" and the meaning of the second can be regarded as \she has no
phone".
In SQL, the NULL value is always false in comparison to any other value, even NULL. An
expression that contains NULL always produces a NULL value unless otherwise indicated in
the documentation for the operators and functions involved in the expression. All columns
in the following example return NULL:
mysql> SELECT NULL,1+NULL,CONCAT('Invisible',NULL);
If you want to search for column values that are NULL, you cannot use the =NULL test. The
following statement returns no rows, because expr = NULL is FALSE, for any expression:
bruce_wang 2003-08-20
  • 打赏
  • 举报
回复
is not null 是正确的。
在MySql中,可以用另一种与法代替:
SELECT COUNT(*) AS nums FROM online WHERE NOT (username <=> NULL)
whyxx 2003-08-20
  • 打赏
  • 举报
回复
实践一下不就知道了,纸上谈兵是没用的
langjianjun 2003-08-20
  • 打赏
  • 举报
回复
是对的。
多看看MYSQL的帮助文档。
hocus 2003-08-20
  • 打赏
  • 举报
回复
惭愧,用了三个月
居然从没写过这样的语句
jkit 2003-08-19
  • 打赏
  • 举报
回复
对的.
yinghuaxingfu 2003-08-19
  • 打赏
  • 举报
回复
:)
hocus 2003-08-19
  • 打赏
  • 举报
回复
孤陋寡闻
回去实验下再说 :)

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧