我是 MYSQL/PHP 新手,我确信这是一个简单的问题。我正在尝试从一个表中计算几个问题和受访者的平均值,并使用该值更新组表。
例如,表答案由我想要的表 B 中的 (name, group_id, TaskClarity1, TaskClarity2, TaskClarity3) 组成 (group_id, avg(TaskClarity1,TaskClarity2,TaskClarity3))。
这就是我所拥有的...
$avg_task_clarity_1 = mysql_query("SELECT AVG(TaskClarity1) WHERE gruppid = '$group_id'");
$avg_task_clarity_2 = mysql_query("SELECT AVG(TaskClarity2) WHERE gruppid = '$group_id'");
$avg_task_clarity_3 = mysql_query("SELECT AVG(TaskClarity3) WHERE gruppid = '$group_id'");
$avg_task_clarity = ($avg_task_clarity_1+$avg_task_clarity_2+$avg_task_clarity_3)/3;
$print_task_clarity_1" UPDATE results SET results.TaskClarity = '$avg_task_clarity'";
if (mysql_query($print_task_clarity_1)) { echo $print_task_clarity_1; } else { echo "Error TaskClarity1: " . mysql_error();