SQL:与< =和> =之间 [英] SQL : BETWEEN vs <= and >=
本文介绍了SQL:与< =和> =之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SQL Server 2000和2005中:
In SQL Server 2000 and 2005:
- 这两个
WHERE
子句之间有什么区别? - 在哪种情况下我应该使用哪个?
- what is the difference between these two
WHERE
clauses? - which one I should use on which scenarios?
查询1:
SELECT EventId, EventName
FROM EventMaster
WHERE EventDate BETWEEN '10/15/2009' AND '10/18/2009'
查询2:
SELECT EventId, EventName
FROM EventMaster
WHERE EventDate >='10/15/2009'
AND EventDate <='10/18/2009'
(第二个Eventdate最初不存在,因此查询在语法上是错误的)
( the second Eventdate was originally missing, so the query was syntactically wrong)
推荐答案
它们是相同的:BETWEEN
是问题中较长语法的简写.
They are identical: BETWEEN
is a shorthand for the longer syntax in the question.
使用替代的更长语法,例如BETWEEN
不起作用
Use an alternative longer syntax where BETWEEN
doesn't work e.g.
Select EventId,EventName from EventMaster
where EventDate >= '10/15/2009' and EventDate < '10/18/2009'
(请注意<
而不是第二个条件下的<=
.)
(Note <
rather than <=
in second condition.)
这篇关于SQL:与< =和> =之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文