今天写作业,有个需求,在Student表中对每一个系,求学生的平均年龄,并把结果存入数据库表Deptage中;
在写下代码后报错
SELECT Sdept,AVG(Sage) /*AVG (Sage)未指定列名*/
INTO Deptage
FROM SC,Student
WHERE SC.Sno=Student.Sno
GROUP BY Sdept
SELECT * FROM Deptage
因为插入的表是新表,所以要指出新表的每一列的列名。
SELECT Sdept,AVG(Sage) AS Avg_Sage/*指定列名为Avg_Sage*/
INTO Deptage
FROM SC,Student
WHERE SC.Sno=Student.Sno
GROUP BY Sdept
SELECT * FROM Deptage
慢慢积累,慢慢沉淀,加油