為什么 mysql 的 where 之間無法使用 = 檢索布爾值?
在 mysql 中,where 子句中布爾值字段的比較必須使用字符串而不是數字。這是因為 enum 值(布爾值類型作為 enum 值存儲)的索引是從 1 開始的,而不是從 0 開始的。
例如,在您提供的表結構中,is_svddb_match 字段是使用 ‘true’(1)和 ‘false’(0)值的 enum 類型:
create table `tmp_rt57517_20230407` ( `video_id` int(10) unsigned not null, `key_id` varchar(64) not null comment 'key id from tracking website', `trackingwebsite_id` smallint(5) unsigned not null comment 'tracking website id', `is_svddb` enum('true','false') not null default 'true' comment 'filter meta by release date', `is_svddb_match` enum('true','false') not null default 'true' comment 'filter meta by release date', `match_count` int(11) default null comment '匹配到幾個母本', primary key (`video_id`) ) engine=innodb default charset=latin1
登錄后復制
當您使用 where 子句比較布爾值字段時,必須使用相應的字符串值。因此,要檢索所有 is_svddb_match 值為 false 的行,您需要使用以下查詢:
SELECT * FROM `tmp_rt57517_20230407` WHERE `is_svddb_match` = 'false';
登錄后復制
使用數字值(例如 where is_svddb_match = 0)將不會返回任何結果。