繁体   English   中英

如果所有三个字段均为“是”,则SQL隐藏结果

[英]SQL hide result if all three fields are 'Yes'

我有一个包含4个字段的MySQL数据库:

id | planchanged | dataremoved | rolloverenabled |
1  | Yes         | Yes         | Yes             |
2  | NULL        |             |                 |
3  |             | Yes         |                 |
4  | Yes         |             | Yes             |
5  |             |             | NULL            |

如何查询此数据库,以仅显示在这三个字段上没有全部“是”的记录。 另请注意,某些字段可能为Null 因此,基于该示例,我的结果应显示记录2、3、4和5。

你可以这样做

SELECT * FROM TableName 
WHERE coalesce(planchanged,'-') <> 'Yes' OR 
coalesce(dataremoved,'-') <> 'Yes' OR
coalesce(rolloverenabled,'-') <>'Yes'

SQL FIDDLE DEMO

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小提琴

SELECT * 
FROM  yourTableName 
WHERE planchanged IS NULL 
  OR  dataremoved IS NULL 
  OR  rolloverenabled IS NULL 
  OR  planchanged <> 'Yes' 
  OR  dataremoved <> 'Yes' 
  OR  rolloverenabled <> 'Yes'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM