簡體   English   中英

如何在mysql中選擇true和false列值

[英]how to select both true and false column value in mysql

我有一個名為 file_download 的表。 我需要顯示

  1. 下載的文件列表 - select * from file_download where downloaded = 1;
  2. 未下載的文件列表 - select * from file_download where downloaded = 0;
  3. 所有文件列表 - 對於所有文件列表,需要提及什么樣的條件?

下面是示例表。

 +----+----------+---------+------------+ | 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 其中下載 = 1 或下載 = 0

使用 IN(簡短而准確的方式)

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

使用不為空(不推薦的方式)

select * from file_download 其中下載的不為空

感謝您的回復...我已經完成了

select * from file_download where download <> ?

? - 對於隨機輸入值 (0, 1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM