MySQL 使用 LIKE 和 WHERE 选择
我有一个传记数据表,我需要执行一个查询,选择在其传记中包含“死亡”一词且死亡日期为 NULL 的人。这是行不通的:
SELECT * FROM people
WHERE bio LIKE '%died%'
AND death_date IS NULL
它选择了 Death_date 为空的每个人,但也选择了简历中没有“死亡”一词的人。我可以在一个查询中完成此操作吗?
I have a table of biographical data, and I need to do a query that selects people who have the word "died" in their bio and whose death date is NULL. This doesn't work:
SELECT * FROM people
WHERE bio LIKE '%died%'
AND death_date IS NULL
That selects everyone whose death_date is null, but also selects people who don't have the word "died" in their bio. Can I do this in one query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能是“完全死亡”之类的词,但他们仍然会被选中。仔细检查您选择的记录中的某些单词中是否不存在“死亡”短语。
It could be a word like 'completelydied' and they are still going to be selected. Check carefully if 'died' phrase does not exists as part of some word in the records that you got selected.
也许问题出在引号上,使用 " 而不是 ' 来包装 LIKE 子句。
Perhaps the problem is the quotes, use " instead of ' to wrap the LIKE clause.
我建议你将生物大写,并像“%DIED%”一样确保death_date确实为空,看看你是否从两个案例中独立得到答案。你得到什么回应?
i would suggest you make bio upper case and have like "%DIED%" also make sure that death_date is really null, see if you get an answer from both where cases independently. What response are you getting?