【发布时间】:2016-10-03 00:41:40
【问题描述】:
我有一个名为 file_download 的表。 我需要显示
- 下载的文件列表-
select * from file_download where downloaded = 1; - 未下载的文件列表 -
select * from file_download where downloaded = 0; - 所有文件列表 - 对于所有文件列表,必须提到什么样的条件?
下面是示例表。
+----+----------+---------+------------+ | 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 | +----+----------+---------+------------+
提前谢谢...
【问题讨论】:
-
嗯,如果
downloaded只能是0或1,那么就不要使用where标准。如果它可以包含另一个值,请使用in--where downloaded in (0,1)... -
@seddes,没有IN,我们还有其他选择吗?
-
WHERE downloaded IN (0,1)是最简洁的方式。你也可以使用WHERE downloaded = 0 OR downloaded = 1,但这太长了。但是,如果下载的只有两个可能的值,则无论如何都没有理由使用WHERE。