Missing 'Median' Aggregate Function in Django?

前端 未结 6 953
孤城傲影
孤城傲影 2021-01-04 13:09

The Development version of Django has aggregate functions like Avg, Count, Max, Min, StdDev, Sum, and Variance (link text). Is there a reason Median is missing from the list

6条回答
  •  醉梦人生
    2021-01-04 13:23

    Well, the reason is probably that you need to track all the numbers to calculate median. Avg, Count, Max, Min, StDev, Sum, and Variance can all be calculated with constant storage needs. That is, once you "record" a number you'll never need it again.

    FWIW, the variables you need to track are: min, max, count, = avg, = avg of the square of the values.

提交回复
热议问题