2016-07-13 20 views
0

に私は現在、最高の平均結果を得るために次のクエリを使用しています:私は最高の加重平均を算出するために、私のクエリを変更しようとしています加重平均は、MySQL

select ContentType, AVG(Result) as AvgContent from dopractice where S_Id [email protected]_Id group by ContentType order by 2 desc limit 1; 

。例えば

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

単一のクエリを使用してこれを行う方法はありますか?

注:dopractice表の列(Id, StudentId, LessonId, ContentType, result, Date)

答えて

-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; 
+0

提案の加重平均をどのように計算しますか? – John