Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem With Create View Statement

Status
Not open for further replies.

anarking

Technical User
Jul 1, 2005
2
IE
I have These tables

CREATE TABLE EMPLOYEE ( EId INT, EName VARCHAR(20), Salary INT, PRIMARY KEY (EId) )

CREATE TABLE WORKS_FOR ( EId INT, PId INT, PRIMARY KEY (PId, EId) )

CREATE TABLE PROJECT ( PId INT, PName VARCHAR(20), Supervisor VARCHAR(20), Budget INT, PRIMARY KEY (PId) )


And I want to for each project, print the sum of the salaries of those employees working for that project and I want to Print also project ID and project name for each project.


I tried Using a Create View statement but I cant work out how to get sum(salary) to be for each Project.


Any ideas?
 
Code:
SELECT p.PId, p.PName, SUM(e.Salary)
FROM WORKS_FOR w
JOIN  PROJECT p ON p.PId = w.PId
JOIN EMPLOYEE e ON e.EID = w.EId
GROUP BY p.PId, p.PName

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top