如何 select mysql 中的 true 和 false 列值

how to select both true and false column value in mysql

我有一个 table 叫 file_download。 我需要显示

  1. 已下载文件列表 - select * from file_download where downloaded = 1;
  2. 未下载文件列表 - select * from file_download where downloaded = 0;
  3. 所有文件列表 - 对于所有文件列表,必须提到什么样的条件?

下面是示例 table。

+----+----------+---------+------------+
| pk | filename |  file   | downloaded |
+----+----------+---------+------------+
|  1 | aaa.txt  | aaa.txt |          1 |
|  2 | bbb.txt  | aaa.txt |          1 |
|  3 | ccc.txt  | aaa.txt |          0 |
|  4 | ccc.txt  | aaa.txt |          1 |
|  5 | ccc.txt  | aaa.txt |          0 |
|  6 | ccc.txt  | aaa.txt |          0 |
+----+----------+---------+------------+

提前致谢...

可以通过三种方式实现同​​样的效果

使用 OR(成本更低)

select * from file_download where downloaded = 1 or downloaded = 0

使用 IN(简短准确的方式)

select * from file_download where downloaded in (0, 1);

使用不为空(不推荐的方式)

select * from file_download where downloaded is not null

感谢您的回复... 我用

完成了

select * 从 file_download 下载的地方 <> ?

? - 对于随机输入值 (0, 1)