【问题标题】:Statistical significance for average values?平均值的统计意义?
【发布时间】:2013-08-10 14:34:10
【问题描述】:

考虑一个投票系统。例如。用于汽车。

  • 10 人认为给汽车A 打分70%。
  • 1000 人认为给汽车A 60% 的分数。

因此,我们有 0.70.6 的值。 您如何比较这些值?毫无疑问,1000 票比 10 票更重要。最好,我想在SQL 中有效地执行此操作(使用AVG 函数或类似函数)。

这类问题应该有一个众所周知的公式。请帮忙!

【问题讨论】:

    标签: sql statistics


    【解决方案1】:

    好的,我们来数一数人数。我们共有 1010 人,其中 1000 人得分 60,而 10 人得分 70。

    平均分是:

    (1000 * 60 + 10 * 70)/(1000 + 10) = 60,09
    

    现在将它们放到表中并对其运行查询:

    create table scores (cust_id int identity(1,1), car char(1), score float);
    go
    
    ------------------------------------------------------
    declare @i int = 0;
    
    while @i < 1000 
    begin
        insert into scores(car, score) values ('A', 60.0);
        set @i = @i + 1
    end
    
    while @i < 1010
    begin
        insert into scores(car, score) values ('A', 70.0);
        set @i = @i + 1
    end;
    
    ------------------------------------------------------
    select car, avg(score) [score], count(cust_id) [people_count]
    from scores
    group by car
    

    结果:

    car score   people_count
    ------------------------
    A   60,09   1010
    

    SQLFiddle


    更新

    create function compare_scores (@n1 int, @sc1 float, @n2 int, @sc2 float)
    returns varchar(10)
    as
    begin
        return case when (@n1 * @sc1) <= (@n2 * @sc2) then (case when (@n1 * @sc1) = (@n2 * @sc2) then 'EQUAL' else 'LESS' end) else 'GREATER' end
    end
    
    ----------------------------------------------------------
    select dbo.compare_scores(10, 10.0, 1000, 8.0) [result]
    union all
    select dbo.compare_scores(10, 10.0, 10, 10.0) [result]
    union all
    select dbo.compare_scores(1000, 10.0, 10, 8.0) [result]
    

    结果:

    result
    -------
    LESS
    EQUAL
    GREATER
    

    【讨论】:

    • 这是总平均分,不是吗?我正在寻找一个“正确”以类似方式比较分数的公式,例如imdb.com 做到了。例如。 10 * 10.0 小于 1000 * 8.0。
    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2015-03-30
    • 2017-02-06
    • 2013-01-14
    • 2012-06-19
    相关资源
    最近更新 更多