where username is not null username字段不为null 当然是对的了 因为大多数的数据库中,对null的判断,都是特出的,用这种方式,而不能用=null的
is not null 是正确的。 在MySql中,可以用另一种与法代替: SELECT COUNT(*) AS nums FROM online WHERE NOT (username <=> NULL)
看看下面这两段关于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:
username字段不为null
当然是对的了
因为大多数的数据库中,对null的判断,都是特出的,用这种方式,而不能用=null的
在MySql中,可以用另一种与法代替:
SELECT COUNT(*) AS nums FROM online WHERE NOT (username <=> 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: