mysql - MySQL where and multi or like
问题描述
这是示例查询:
select
email,
firstName,
lastName
from
users
where
createdAt between '2020-04-01 00:00:00.0' and '2020-09-30 23:59:59.0'
or email like '%bob%'
or firstName like '%bob%'
or lastName like '%bob%'
order by
createdAt desc
我得到的结果例如:
remi10@martin10.com,remi10,martin10
remi6@martin6.com,Bobby,martin6
remi5@gmail.com,Bob,martin5
remi4@gmail.com,remi4,martin4
我试图得到...
remi6@martin6.com,Bobby,martin6
remi5@gmail.com,Bob,martin5
它应该返回在%bob%
提供的日期/时间段之间的记录。
解决方案
它应该返回在提供的日期/时间段之间具有 %bob% 的记录。
您需要and
在日期过滤器和多个类似条件之间。我还建议使用半开间隔过滤来简化日期过滤器:
where
createdAt >= '2020-04-01'
and createdAt < '2020-10-01'
and (
email like '%bob%'
or firstName like '%bob%'
or lastName like '%bob%'
)
推荐阅读
- auraphp - Aura 路由器 AJAX 路由失败 - 找不到路由
- minizinc - 如何在 minizinc 中使用 R 或 python 生成 .dzn 文件
- python - np.where 数据框列 .isin 数据框列
- hadoop - 仅在“-Dorg.apache.sqoop.splitter.allow_text_splitter=true”属性作为参数传递的情况下才允许为文本索引列生成拆分
- c# - 用于按下按钮问题的 C# 可调热键功能
- llvm - 在一个头文件中创建具有 extern 的 GlobalVariable
- azure - 如何在 MVC 5 应用程序的 azure 自动缩放环境中实现 redis 会话提供程序?
- php - 在动态数据库加载代码中包含静态 html 图像
- r - 使用“for 循环”在 R 中运行一系列线性回归
- c# - 在 C# 中调用 COM 方法会引发无法解释的 COMException,在 C++ 中可以正常工作