你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Applies to: ✅Microsoft Fabric✅Azure Data Explorer✅Azure Monitor✅Microsoft Sentinel
生成值的单列表。
Note
此运算符不采用表格输入。
Syntax
range
columnNamefromstarttostopstepstep
Learn more about syntax conventions.
Parameters
| Name | 类型 | Required | Description |
|---|---|---|---|
| columnName | string |
✔️ | 输出表中的单列名称。 |
| start | int、long、real、datetime 或 timespan | ✔️ | 输出中的最小值。 |
| stop | int、long、real、datetime 或 timespan | ✔️ | The highest value being generated in the output or a bound on the highest value if step is over this value. |
| step | int、long、real、datetime 或 timespan | ✔️ | 两个连续值之间的差异。 |
Note
这些值不能引用任何表的列。 If you want to compute the range based on an input table, use the range function potentially with the mv-expand operator.
Returns
A table with a single column called columnName, whose values are start, start+step, ... up to and until stop.
Examples
本节中的示例演示如何使用语法帮助你入门。
The examples in this article use publicly available tables in the help cluster, such as the
StormEventstable in the Samples database.
The examples in this article use publicly available tables, such as the
Weathertable in the Weather analytics sample gallery. 可能需要修改示例查询中的表名称以匹配工作区中的表。
过去七天的范围
以下示例创建一个表,其中包含过去七天内延长的当前时间戳的条目,每天一次。
range LastWeek from ago(7d) to now() step 1d
Output
| LastWeek |
|---|
| 2015-12-05 09:10:04.627 |
| 2015-12-06 09:10:04.627 |
| ... |
| 2015-12-12 09:10:04.627 |
合并不同的停止时间
以下示例演示如何使用 union 运算符扩展范围以使用多次停止时间。
let Range1 = range Time from datetime(2024-01-01) to datetime(2024-01-05) step 1d;
let Range2 = range Time from datetime(2024-01-06) to datetime(2024-01-10) step 1d;
union Range1, Range2
| order by Time asc
Output
| Time |
|---|
| 2024-01-04 00:00:00.0000000 |
| 2024-01-05 00:00:00.0000000 |
| 2024-01-06 00:00:00.0000000 |
| 2024-01-07 00:00:00.0000000 |
| 2024-01-08 00:00:00.0000000 |
| 2024-01-09 00:00:00.0000000 |
| 2024-01-10 00:00:00.0000000 |
使用参数的范围
以下示例演示如何将 range 运算符与参数配合使用,这些参数随后会作为表进行扩展和使用。
let toUnixTime = (dt:datetime)
{
(dt - datetime(1970-01-01)) / 1s
};
let MyMonthStart = startofmonth(now()); //Start of month
let StepBy = 4.534h; //Supported timespans
let nn = 64000; // Row Count parametrized
let MyTimeline = range MyMonthHour from MyMonthStart to now() step StepBy
| extend MyMonthHourinUnixTime = toUnixTime(MyMonthHour), DateOnly = bin(MyMonthHour,1d), TimeOnly = MyMonthHour - bin(MyMonthHour,1d)
; MyTimeline | order by MyMonthHour asc | take nn
Output
| MyMonthHour | MyMonthHourinUnixTime | DateOnly | TimeOnly |
|---|---|---|---|
| 2023-02-01 | 00:00:00.0000000 | 1675209600 | 2023-02-01 00:00:00.0000000 |
| 2023-02-01 | 04:32:02.4000000 | 1675225922.4 | 2023-02-01 00:00:00.0000000 |
| 2023-02-01 | 09:04:04.8000000 | 1675242244.8 | 2023-02-01 00:00:00.0000000 |
| 2023-02-01 | 13:36:07.2000000 | 1675258567.2 | 2023-02-01 00:00:00.0000000 |
| ... | ... | ... | ... |
Incremented steps
以下示例创建一个表,其中包含一个名为 Steps 的列,其类型为 long,并导致值从 1 到 8 递增 3。
range Steps from 1 to 8 step 3
Output
| Steps |
|---|
| 1 |
| 4 |
| 7 |
时间范围内的跟踪
以下示例演示如何使用 range 运算符创建一个维度表,该表用于在源数据没有值的情况下引入零。 它采用过去四个小时的时间戳,并计算每一分钟间隔的跟踪数。 当特定间隔没有跟踪时,计数为零。
range TIMESTAMP from ago(4h) to now() step 1m
| join kind=fullouter
(Traces
| where TIMESTAMP > ago(4h)
| summarize Count=count() by bin(TIMESTAMP, 1m)
) on TIMESTAMP
| project Count=iff(isnull(Count), 0, Count), TIMESTAMP
| render timechart