1

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

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

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

4

3 回答 3

3

你可以这样做

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

SQL小提琴演示

于 2013-01-14T02:21:48.043 回答
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'

SQL小提琴

于 2013-01-14T02:27:37.777 回答
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'
于 2013-01-14T02:20:12.383 回答