我试图创建一个Table Function Total_Salary_By_Dept,它返回一个包含5列的表Total_Salary_By_Dept_Table:
Dept_No (Int)
Dept_Name (Char(30))
COUNT_Emp (INT)
SUM_Salary (INT)
AVE_Salary (INT)
所有公司数据库;
这是我到目前为止所做的,不确定我是否正确:
Use Company
GO
CREATE FUNCTION Total_Salary_By_Dept ()
RETURNS @Total_Salary_By_Dept_Table TABLE
(
Dept_No int,
Dept_name char(30),
COUNT_Emp int,
Sum_Salary int,
AVE_Salary int
)
AS
BEGIN
INSERT INTO @Total_Salary_By_Dept_Table
Select e.Dept_No, d.Dept_Name, Count(e.Dept_No), SUM(e.salary) as Sum_Salary,AVG(e.salary) as AVE_Salary
from EMPLOYEE e
join DEPARTMENT d ON e.dno = d.dnumber
Group by e.Dept_No, d.Dept_Name
RETURN
END
但是我得到了这个错误输出:
Msg 207, Level 16, State 1, Procedure Total_Salary_By_Dept, Line 18
Invalid column name 'Dept_No'.
Msg 207, Level 16, State 1, Procedure Total_Salary_By_Dept, Line 18
Invalid column name 'Dept_Name'.
Msg 207, Level 16, State 1, Procedure Total_Salary_By_Dept, Line 15
Invalid column name 'Dept_No'.
Msg 207, Level 16, State 1, Procedure Total_Salary_By_Dept, Line 15
Invalid column name 'Dept_Name'.
Msg 207, Level 16, State 1, Procedure Total_Salary_By_Dept, Line 15
Invalid column name 'Dept_No'.
我输错了什么吗?我也以正确的方式完成了我的功能吗?请给我建议!