我有一个查询,计算不包括某些值的记录数,我尝试使用 <>
, NOT LIKE
和NOT 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/