为多关系表创建视图sql-server?

时间:2018-12-23 22:54:08

标签: sql-server database

我想创建一个视图以显示该部门的部门名称,员工数,总薪水和项目数

database digram

这是我的查询,但没有返回数据:

SELECT  d.[DeprtmentName] ,
    count(e.[Id]) AS Employees,
    sum(e.[Salary]) AS [Total Salary],
    count(p.[Id]) AS Pojects
FROM [dbo].[Department] as d
join [dbo].[Employee] as e on d.id = e.[DeptId]
join [dbo].[ProjectEmployee] as p on e.id = p.[EmployeeId]
join [dbo].[Project] on p.[ProjectId] = [dbo].[Project].[Id] 
group by (d.[DeprtmentName]) 

0 个答案:

没有答案