共用方式為


range 運算子

產生單一資料行的值資料表。

注意

此運算子不會採用表格式輸入。

語法

rangecolumnNamefromstarttostopstepstep

深入瞭解 語法慣例

參數

名稱 類型 必要 Description
columnName string ✔️ 輸出數據表中單一數據行的名稱。
開始 int、long、real、datetime 或 timespan ✔️ 輸出中的最小值。
停止 int、long、real、datetime 或 timespan ✔️ 如果 逐步 執行此值,則會在輸出中產生最高值或系結的最高值。
int、long、real、datetime 或 timespan ✔️ 兩個連續值之間的差異。

注意

這些值無法參考任何數據表的數據行。 如果您想要根據輸入數據表來計算範圍,請使用 範圍 函數搭配 mv-expand 運算元。

傳回

單一資料行稱為 columnName 的資料表,其值為 startstart+step、 ... up to 和 until stop

範例

下列範例會建立數據表,其中包含過去七天一天一次延伸之目前時間戳的專案。

range LastWeek from ago(7d) to now() step 1d

輸出

LastWeek
2015-12-05 09:10:04.627
2015-12-06 09:10:04.627
...
2015-12-12 09:10:04.627

下列範例示範如何使用 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

輸出

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
... ... ... ...

下列範例會建立一個數據表,其類型為 1long 且其值為、 47的單一數據行Steps

range Steps from 1 to 8 step 3

下列範例示範 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