本文介绍了SQL : BETWEEN vs <= 和 >=的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL Server 2000 和 2005 中:

In SQL Server 2000 and 2005:

  • 这两个 WHERE 子句有什么区别?
  • 我应该在哪些场景中使用哪个?

查询 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 是问题中较长语法的简写,其中包含两个值 (EventDate >= '10/15/2009' 和 EventDate ).

They are identical: BETWEEN is a shorthand for the longer syntax in the question that includes both values (EventDate >= '10/15/2009' and EventDate <= '10/19/2009').

使用另一种更长的语法,其中 BETWEEN 不起作用,因为不应包含一个或两个值,例如

Use an alternative longer syntax where BETWEEN doesn't work because one or both of the values should not be included e.g.

Select EventId,EventName from EventMaster
where EventDate >= '10/15/2009' and EventDate < '10/19/2009'

(注意 < 而不是 在第二个条件中.)

(Note < rather than <= in second condition.)

这篇关于SQL : BETWEEN vs &lt;= 和 &gt;=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 20:00