【问题标题】:weighted average in MySqlMySql中的加权平均值
【发布时间】:2016-07-13 13:10:47
【问题描述】:

我目前正在使用以下查询来获得最高的平均结果:

select ContentType, AVG(Result) as AvgContent from dopractice where S_Id =@S_Id group by ContentType order by 2 desc limit 1; 

我正在尝试修改我的查询以计算最高加权平均值。

例如:

((X*1)+(Y*2)+(Z*3))/3

有没有办法使用单个查询来做到这一点?

注意:dopractice 表中的列是(Id, StudentId, LessonId, ContentType, result, Date)

【问题讨论】:

    标签: mysql select average


    【解决方案1】:

    试试这个代码。可能对你有帮助。

        select temp.content,MAX(temp.AvgContent)
        FROM
        (
        select ContentType AS content, AVG(Result) as AvgContent 
        from dopractice 
        where StudentId = @S_Id 
        group by ContentType order by ContentType desc
        ) AS temp
       group by  temp.ContentType;
    

    【讨论】:

    • 如何计算建议中的加权平均值?
    猜你喜欢
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2015-07-15
    相关资源
    最近更新 更多