MYSQL where 子句中的条件
问题描述
我有一个查询,如果名为 OrderBy 的标志为 1,那么它是一个日历事件,我需要检查两个日期时间字段之间的范围.而所有其他类型我们只检查您正在查看的日期.我研究了 if 语句,并看到许多建议使用案例的帖子,因此我尝试将其实现到我的查询中.我的查询需要 where 的条件.我知道我有语法问题,这就是为什么我在这里希望有人能指出正确的方法.
I have a query that if a flag called OrderBy is 1 then it is a calendar event and I need to check for a range between two date time fields. Whereas all other types we just check for the day you are viewing. I research if statements and saw many posts where it was suggested a case be used so I tried to implement it into my query. My query needs the condition in the where. I know I have syntax issues and that is why I am here in the hopes that someone could point out the correct way to do this.
感谢您的宝贵时间
我的查询目前
推荐答案
只要使用足够的括号,您就可以使用 AND
和 OR
来做到这一点.
You can do this with AND
and OR
as long as you use sufficient parentheses.
我还假设 activities.OrderBy
可以为空.如果不是这种情况,您可以删除空检查:
Also I'm assuming that activities.OrderBy
can be null. If that's not the case you can remove the null check:
或者,如果您仍想使用 CASE
,您只需使用 END
关闭您的 CASE
语句,如下所示:
Alternatively, if you still want to use CASE
, you just need to close your CASE
statement using END
, like this:
这篇关于MYSQL where 子句中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!