我有一个包含4个字段的MySQL数据库:
id | planchanged | dataremoved | rolloverenabled |
1 | Yes | Yes | Yes |
2 | NULL | | |
3 | | Yes | |
4 | Yes | | Yes |
5 | | | NULL |
如何查询此数据库以仅显示在这三个字段中没有全部为“是”的记录。另请注意,某些字段可能 Null 。因此,根据该示例,我的结果应显示记录2,3,4和5。
答案 0 :(得分:3)
你可以这样做
SELECT * FROM TableName
WHERE coalesce(planchanged,'-') <> 'Yes' OR
coalesce(dataremoved,'-') <> 'Yes' OR
coalesce(rolloverenabled,'-') <>'Yes'
SQL FIDDLE DEMO
答案 1 :(得分:3)
SELECT *
FROM yourTableName
WHERE planchanged IS NULL OR planchanged <> 'Yes'
OR dataremoved IS NULL OR dataremoved <> 'Yes'
OR rolloverenabled IS NULL OR rolloverenabled <> 'Yes'
答案 2 :(得分:0)
SELECT *
FROM yourTableName
WHERE planchanged IS NULL
OR dataremoved IS NULL
OR rolloverenabled IS NULL
OR planchanged <> 'Yes'
OR dataremoved <> 'Yes'
OR rolloverenabled <> 'Yes'