SELECT * FROM Persons
WHERE LastName
BETWEEN 'Adams' AND 'Carter'不同的数据库对 BETWEEN...AND 操作符的处理方式是有差异的。某些数据库会列出介于 "Adams" 和 "Carter" 之间的人,但不包括 "Adams" 和 "Carter" ;某些数据库会列出介于 "Adams" 和 "Carter" 之间并包括 "Adams" 和 "Carter" 的人;而另一些数据库会列出介于 "Adams" 和 "Carter" 之间的人,包括 "Adams" ,但不包括 "Carter" 。想知道哪些数据库中表示的是那种情况
oracle
mysql
sql server2000

解决方案 »

  1.   

    mysql:
    expr BETWEEN min AND max 
    假如expr大于或等于 min 且expr 小于或等于max, 则BETWEEN 的返回值为1,或是0。若所有参数都是同一类型,则上述关系相当于表达式   (min <= expr AND expr <= max)。其它类型的转换根据本章开篇所述规律进行,且适用于3种参数中任意一种。  
      

  2.   

    只回答SQL的:包含输入参数的边界。注意一种误区:日期有带时间的时候,如:'2010-04-21 16:42:39','2010-04-23 16:42:39' 往往会 between '2010-04-21' and '2010-04-23'  这样'2010-04-23 16:42:39' 这条记录就查不到,因为它的边界值是'2010-04-23 00:00:00' 
      

  3.   

    oracleYou use the BETWEEN operator in a WHERE clause to select rows whose column value is inclusive within a specified range. The following example uses the BETWEEN operator to retrieve rows from the customers table where the customer_id column is between 1 and 3:SELECT *
    FROM customers
    WHERE customer_id BETWEEN 1 AND 3;CUSTOMER_ID FIRST_NAME LAST_NAME  DOB       PHONE
    ----------- ---------- ---------- --------- ------------
              1 John       Brown      01-JAN-65 800-555-1211
              2 Cynthia    Green      05-FEB-68 800-555-1212
              3 Steve      White      16-MAR-71 800-555-1213The range specified with the BETWEEN operator is inclusive so the rows where the customer_id column is equal to 1, 2, or 3 are retrieved. As you’d expect, NOT BETWEEN reverses the rows retrieved.
      

  4.   

    sql serverBETWEEN
    指定测试范围。语法
    test_expression [ NOT ] BETWEEN begin_expression AND end_expression参数
    test_expression是用来在由 begin_expression 和 end_expression 定义的范围内进行测试的表达式。test_expression 必须与 begin_expression 和 end_expression 具有相同的数据类型。NOT指定谓词的结果被取反。begin_expression是任何有效的 Microsoft® SQL Server™ 表达式。begin_expression 必须与 test_expression 和 end_expression 具有相同的数据类型。end_expression是任何有效的 SQL Server 表达式。end_expression 必须与 test_expression 和 begin_expression 一样具有相同的数据类型。AND作为一个占位符,表示 test_expression 应该处于由 begin_expression 和 end_expression 指定的范围内。结果类型
    Boolean结果值
    如果 test_expression 的值大于或等于 begin_expression 的值并且小于或等于 end_expression 的值,则 BETWEEN 返回 TRUE。如果 test_expression 的值小于 begin_expression 的值或者大于 end_expression 的值,则 NOT BETWEEN 返回 TRUE。注释
    若要指定排除范围,请使用大于 (>) 和小于 (<) 运算符。如果任何 BETWEEN 或 NOT BETWEEN 谓词的输入为 NULL,则结果是 UNKNOWN。
      

  5.   

    sybase
    BETWEEN 条件--------------------------------------------------------------------------------BETWEEN 条件的语法如下:expr [ NOT ] BETWEEN start-expr AND end-exprBETWEEN 条件的值可以是 TRUE、FALSE 或 UNKNOWN。无关键字 NOT 时,如果 expr 介于 start-expr 和 end-expr之间,条件的值为 TRUE。NOT 关键字使条件的含义相反,但保留 UNKNOWN 不变。BETWEEN 条件相当于两个不等式的组合:[ NOT ] ( expr >= start-expr AND expr <= end-expr ) 标准和兼容性
    BETWEEN 条件在 Adaptive Server Anywhere 和 Adaptive Server Enterprise 之间兼容。
      

  6.   

    postgresql:In addition to the comparison operators, the special BETWEEN construct is available: a BETWEEN x AND y
    is equivalent to a >= x AND a <= y
    Notice that BETWEEN treats the endpoint values as included in the range. NOT BETWEEN does the opposite comparison: a NOT BETWEEN x AND y
    is equivalent to a < x OR a > y
    BETWEEN SYMMETRIC is the same as BETWEEN except there is no requirement that the argument to the left of AND be less than or equal to the argument on the right. If it is not, those two arguments are automatically swapped, so that a nonempty range is always implied.