2

ローカル サーバーに単純なテーブルがあります。

mysql> desc table ;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(10) | YES  |     | NULL    |       | 
| count | int(10) | YES  |     | NULL    |       | 
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec

その中には 3 つのレコードしかありません。

mysql> select * from uday ;
+------+-------+
| id   | count |
+------+-------+
|    1 |     1 | 
|    2 |     2 | 
|    3 |     0 | 
|    4 |  NULL | 
+------+-------+
4 rows in set (0.00 sec)

さて、以下の結果で 4 番目の列が表示されないのはなぜですか..?

mysql> select * from uday where count NOT IN (0) ;
mysql> select * from uday where count != 0 ;
+------+-------+
| id   | count |
+------+-------+
|    1 |     1 | 
|    2 |     2 | 
+------+-------+
2 rows in set (0.00 sec)

4枚目はどうですか…?結果には表示されません。NULL は 0 ではありませんよね...?

私はコーディングの部分でさえ競争力がないので、それがかなりばかげているように見える場合は無視してください。

4

1 に答える 1

3
col1 not in (1,2,null)

は次の省略形です。

col1 <> 1 and col1 <> 2 and col1 <> null

SQL の3 値ロジックでは、 をcol1 <> null返しますunknown。またtrue and true and unknown、 を返しますunknownwhereのみを受け入れtrue、 は受け入れないためunknown、 を含む行nullは結果セットから除外されます。

于 2012-04-05T11:11:35.093 に答える