Standard Deviation for SQLite

后端 未结 10 715
生来不讨喜
生来不讨喜 2020-12-14 08:05

I\'ve searched the SQLite docs and couldn\'t find anything, but I\'ve also searched on Google and a few results appeared.

Does SQLite have any built-in Standard Devi

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 08:44

    You don't state which version of standard deviation you wish to calculate but variances (standard deviation squared) for either version can be calculated using a combination of the sum() and count() aggregate functions.

    select  
    (count(val)*sum(val*val) - (sum(val)*sum(val)))/((count(val)-1)*(count(val))) as sample_variance,
    (count(val)*sum(val*val) - (sum(val)*sum(val)))/((count(val))*(count(val))) as population_variance
    from ... ;
    

    It will still be necessary to take the square root of these to obtain the standard deviation.

提交回复
热议问题