between 运算符between operator

匹配包含范围内的输入。Matches the input that is inside the inclusive range.

Table1 | where Num1 between (1 .. 10)
Table1 | where Time between (datetime(2017-01-01) .. datetime(2017-01-01))

between 可以对任何数值、日期时间或时间跨度表达式执行运算。between can operate on any numeric, datetime, or timespan expression.

语法Syntax

T | where expr between (leftRange..rightRange)T | where expr between (leftRange..rightRange)

如果 expr 表达式为时间跨度,则提供另一个糖衣语法:If expr expression is datetime - another syntactic sugar syntax is provided:

T | where expr between (leftRangeDateTime..rightRangeTimespan)T | where expr between (leftRangeDateTime..rightRangeTimespan)

参数Arguments

  • T - 待匹配记录的表格输入。T - The tabular input whose records are to be matched.
  • expr - 要筛选的表达式。expr - the expression to filter.
  • leftRange - 左侧范围(含)的表达式。leftRange - expression of the left range (inclusive).
  • rightRange - 右侧范围(含)的表达式。rightRange - expression of the right range (inclusive).

返回Returns

T 中谓词(expr >= leftRange 和 expr <= rightRange)的行的计算结果为 trueRows in T for which the predicate of ( expr >= leftRange and expr <= rightRange ) evaluates to true.

示例Examples

使用“between”运算符筛选数值Filtering numeric values using 'between' operator

range x from 1 to 100 step 1
| where x between (50 .. 55)
xx
5050
5151
5252
5353
5454
5555

使用“between”运算符筛选日期时间Filtering datetime using 'between' operator

StormEvents
| where StartTime between (datetime(2007-07-27) .. datetime(2007-07-30))
| count 
计数Count
476476
StormEvents
| where StartTime between (datetime(2007-07-27) .. 3d)
| count 
计数Count
476476