MySQLでやりたいとおもいます。まずは、テーブルとデータを用意します。
create table users (
id int,
name text,
level float comment '0~1の間の少数'
);
insert users values
(1, 'taro', 0.2),
(2, 'yuki', 0.2),
(3, 'ken', 0.5),
(4, 'tera', null)
;
mysql> select * from users;
+------+------+-------+
| id | name | level |
+------+------+-------+
| 1 | taro | 0.20 |
| 2 | yuki | 0.20 |
| 3 | ken | 0.50 |
| 4 | tera | NULL |
+------+------+-------+
次の2つのコマンドの結果は何でしょう?
select count(*) from users where level != null;
select count(*) from users where level != 0.2;
答え
0
3
解説
0.2 は float だと、2進数世界において無限小数となる。 decimal(x,y)
を使うことで回避できたりします。