我有一个包含4个字段的MySQL db:
id | planchanged | dataremoved | rolloverenabled |
1 | Yes | Yes | Yes |
2 | NULL | | |
3 | | Yes | |
4 | Yes | | Yes |
5 | | | NULL |如何查询这个数据库,使其只显示在这三个字段中没有全部“是”的记录。也请考虑到其中一些字段可能是空的。基于这个例子,我的结果应该显示记录2,3,4和5。
发布于 2013-01-14 02:27:37
SELECT *
FROM yourTableName
WHERE planchanged IS NULL OR planchanged <> 'Yes'
OR dataremoved IS NULL OR dataremoved <> 'Yes'
OR rolloverenabled IS NULL OR rolloverenabled <> 'Yes'SQL Fiddle
发布于 2013-01-14 02:21:48
你能做到的
SELECT * FROM TableName
WHERE coalesce(planchanged,'-') <> 'Yes' OR
coalesce(dataremoved,'-') <> 'Yes' OR
coalesce(rolloverenabled,'-') <>'Yes'SQL 小提琴演示
发布于 2013-01-14 02:20:12
SELECT *
FROM yourTableName
WHERE planchanged IS NULL
OR dataremoved IS NULL
OR rolloverenabled IS NULL
OR planchanged <> 'Yes'
OR dataremoved <> 'Yes'
OR rolloverenabled <> 'Yes'https://stackoverflow.com/questions/14310571
复制相似问题