Skip to content

Query the population covariance and sample covariance of the pre-tax profit and pre-tax amount from bills

To query the population covariance and sample covariance, perform the following operations: Use the time_series function to aggregate the data by time, use the covar_pop function to calculate the population covariance, and then use the covar_samp function to calculate the sample covariance. The results are displayed in a line chart.

SQL
source :bill |
select
  covar_samp(PretaxGrossAmount, PretaxAmount) as "Sample covariance",
  covar_pop(PretaxGrossAmount, PretaxAmount) as "Population covariance" ,
time_series(__time__, '1m', '%H:%i:%s', '0') as time GROUP BY time