mysql - 无法使用 NOT IN 排除值

标签 mysql

我有一个查询,计算不包括某些值的记录数,我尝试使用 <> , NOT LIKENOT IN但运气不好,这些值仍然显示。

SELECT * 
FROM `stmaintble` 
WHERE `stantithromb` <> 'Non prescribed' 
AND `stantithromb` <> 'Aspirin  75-150 mg'

还尝试过:

SELECT * 
FROM `stmaintble` 
WHERE `stantithromb` NOT IN('Non prescribed', 'Aspirin  75-150 mg')

这也不起作用:

SELECT * 
FROM `stmaintble` 
WHERE `stantithromb` NOT IN('Non prescribed, Aspirin  75-150 mg')

感谢您的帮助。

最佳答案

如果 stantithromb 在该字段中有其他文本(即值看起来像“未处方某种药物”)。然后您需要使用通配符 LIKE 搜索:

SELECT * 
FROM stmaintble 
WHERE stantithromb NOT LIKE '%Non prescribed%' 
  AND stantithromb NOT LIKE '%Aspirin  75-150 mg%'

关于mysql - 无法使用 NOT IN 排除值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27906685/

相关文章:

php - 1路加密和2路加密

java - 解析mysql控制台输出

php - 一次提交多行mysql

Mysql:从2个表中获取结果

javascript - 如何使用javascript格式进行日期选择?

mysql - 命令不能用作别名

数据库值中的 PHP 大括号

MYSQL 从每个类别中选择一个随机记录

PHP-解析错误 : syntax error, 意外 'readphp' (T_STRING),期望 ',' 或 ';'

php - _POST 方法返回 ???当请求utf8字符时