MySQL 使用 LIKE 和 WHERE 选择

发布于 2024-10-03 13:39:35 字数 225 浏览 2 评论 0原文

我有一个传记数据表,我需要执行一个查询,选择在其传记中包含“死亡”一词且死亡日期为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不羁少年 2024-10-10 13:39:35

可能是“完全死亡”之类的词,但他们仍然会被选中。仔细检查您选择的记录中的某些单词中是否不存在“死亡”短语。

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.

爱的那么颓废 2024-10-10 13:39:35

也许问题出在引号上,使用 " 而不是 ' 来包装 LIKE 子句。

SELECT * FROM people
WHERE bio LIKE "%died%"
AND death_date IS NULL

Perhaps the problem is the quotes, use " instead of ' to wrap the LIKE clause.

SELECT * FROM people
WHERE bio LIKE "%died%"
AND death_date IS NULL
迷路的信 2024-10-10 13:39:35

我建议你将生物大写,并像“%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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文