Clickhouse计算平均值

时间:2019-03-06 06:04:13

标签: average clickhouse

我有两个字段,一个是时间戳,另一个是网络总和(以字节为单位)。

timestamp      network_in_bytes
1551196802144   1
1551196802145   5 
1551196802147   18 
1551196802158   80

我要计算(B> A)

avg_network_in_bytes=(network_in_bytes_B-network_in_bytes_A)/(timestamp_B-timestamp_A). 

如何获取avg_network_in_bytes?

1 个答案:

答案 0 :(得分:0)

查看此功能https://clickhouse.yandex/docs/ru/query_language/functions/other_functions/#runningdifference-x

您可以尝试执行以下操作:

select 
  timestamp,
  network_in_bytes,
  runningDifference(timestamp) as timestamp_diff,
  runningDifference(network_in_bytes) as bytes_diff,
  bytes_diff / timestamp_diff
from (
  select
    timestamp,
    network_in_bytes
  from table
  order by timestamp 
)