どのようにMySQLデータベースの更新で複数の数学の方程式を行うには?

ウスマン地:

私は、MySQLデータベースの行を持っている記憶試み、ゲームの平均スコア:

+-----+----------+-----------+
| uid | attempts | avg_score |
|  4  |    3     |    15     |
+-----+----------+-----------+

ユーザがゲームを終えた後、私は新しい試みに基づいて新しい平均を把握する2つのテーブルを更新します。:私がしたい
多重(試行* avg_score = 45)
合計avg_score(avg_score(45)+ trial_score(5)= 50)にtrial_scoreを追加
分割(avg_score(45)+ trial_score(5)/試み=試み+ 1)

これは、PHPのmySQL文でビット私の頭の上にあります。私は以下の私の試みを表示します。

$sql=("UPDATE gamescore SET attempts = attempts + 1,avg_score = ((attempts * avg_score + ?) / (attempts = attempts + 1)) WHERE uid=?");
$stmt = $conn->prepare($sql);
$stmt->bind_param("ii",$_POST['trial_score'],$_SESSION['uid']);
$stmt->execute();

失敗しました。..明らかに...私はここに訂正する必要がありますか?ありがとう!

離れて渡します:

あなたはと分けなければなりませんまた、の値を設定後、最初とは、あなたが設定している場合ので、まずの値に設定式の値MySQLが変更を使用します(あなたはもっと見つけることができるここに):(attempts + 1)(attempts = attempts + 1)
avg_scoreattemptsattemptsavg_scoreattempts

UPDATE gamescore  
SET avg_score = (attempts * avg_score + ?) / (attempts + 1),
    attempts = attempts + 1 
WHERE uid = ?;

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=402875&siteId=1