全部产品
阿里云办公

BETWEEN AND

更新时间:2018-09-30 17:52:21

语法

  1. A BETWEEN B AND C

入参

  • A,B,C

    DOUBLE,BIGINT,INT,VARCHAR,DATE,TIMESTAMP,TIME 类型。

功能描述

BETWEEN操作符用于选取介于两个值之间的数据范围内的值。

示例一

  • 测试数据
int1(INT) int2(INT) int3(INT)
90 80 100
11 10 7
  • 测试案例
  1. SELECT int1 as aa
  2. FROM T1
  3. WHERE int1 BETWEEN int2 AND int3;
  • 测试结果
aa(int)
90

示例二

  • 测试数据
var1(varchar) var1(varchar) var1(varchar)
b a c
  • 测试案例
  1. SELECT var1 as aa
  2. FROM T1
  3. WHERE var1 BETWEEN var2 AND var3;
  • 测试结果
aa(varchar)
b

示例三

  • 测试数据
TIMESTAMP1(TIMESTAMP) TIMESTAMP2(TIMESTAMP) TIMESTAMP3(TIMESTAMP)
1969-07-20 20:17:30 1969-07-20 20:17:20 1969-07-20 20:17:45
  • 测试案例
  1. SELECT TIMESTAMP1 as aa
  2. FROM T1
  3. WHERE TIMESTAMP1 BETWEEN TIMESTAMP2 AND TIMESTAMP3;
  • 测试结果
aa(TIMESTAMP)
1969-07-20 20:17:30