我有一個 MySQL 數(shù)據(jù)庫行,用于存儲游戲的嘗試次數(shù)和平均得分:+-----+----------+-----------+| uid | attempts | avg_score || 4 | 3 | 15 |+-----+----------+-----------+用戶完成游戲后,我想更新這兩個表以根據(jù)新的嘗試計算出新的平均值。我想:乘以(嘗試* avg_score = 45)將trial_score添加到總avg_score(avg_score(45)+ trial_score(5)= 50)除以(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 數(shù)據(jù)庫更新中執(zhí)行多個數(shù)學方程式?
慕碼人8056858
2022-12-03 10:40:48