如何创建一个新表,该表根据名称获取其他表中列的平均值

时间:2013-02-10 20:39:17

标签: mysql

CREATE TABLE Average_Professor

SELECT ie.Instructor
      ,SUM(ie.instreffective_avg + h.howmuchlearned_avg + ir.instrrespect_avg +
 iv.instroverall_avg + av.availability_avg)/5
FROM   instreffective_average ie
JOIN   howmuchlearned_average h  USING (Instructor)
JOIN   instrrespect_average   ir USING (Instructor)
JOIN   instructoroverall_average   iv USING (Instructor)
JOIN   availability_average   av USING (Instructor)
GROUP  BY Instructor

它给了我错误代码1166.如果我省略“CREATE TABLE Professor_average”然后脚本运行,但我没有创建表。

1 个答案:

答案 0 :(得分:1)

尝试命名计算列:

CREATE TABLE Average_Professor
SELECT ie.Instructor
      ,SUM(ie.instreffective_avg + h.howmuchlearned_avg + ir.instrrespect_avg +
 iv.instroverall_avg + av.availability_avg)/5 as calculation_value
FROM   instreffective_average ie
JOIN   howmuchlearned_average h  USING (Instructor)
JOIN   instrrespect_average   ir USING (Instructor)
JOIN   instructoroverall_average   iv USING (Instructor)
JOIN   availability_average   av USING (Instructor)
GROUP  BY Instructor