

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 時間序列函數
<a name="CWL_QuerySyntax-timeseries-functions"></a>

搭配 `stats`命令使用時間序列函數，以分析一段時間內的指標和運算變化率。


|  函式 |  結果類型 |  說明 | 
| --- | --- | --- | 
| `rate(fieldName: NumericLogField, interval: Period)` | number | 計算數值欄位的每個間隔變更率。 | 
| `count_over_time(fieldName: LogField)` | number | 每個時間儲存貯體的日誌事件計數。使用 搭配 `by bin(interval)` 來設定視窗。 | 
| `sum_over_time(fieldName: NumericLogField)` | number | 每個時間儲存貯體的摘要欄位值。使用 搭配 `by bin(interval)` 來設定視窗。 | 
| `histogram(fieldName: NumericLogField, buckets: number)` | 映射 | 將數值欄位值歸納為指定數量的等寬範圍，並傳回分佈。 | 

## offset
<a name="CWL_QuerySyntax-timeseries-offset"></a>

`offset` 在`stats ... by bin()`子句結尾使用 ，將時間序列儲存貯體轉移指定的持續時間。這可啟用時間轉移比較，例如比較目前指標與前一小時或前一天的相同期間。

**語法**

```
stats <aggregation> by bin(<period>) offset <duration>
```

**範例**

```
stats count(*) by bin(5m) offset 1h
```

```
stats avg(latency) by bin(1m) offset 1d
```