Hello, i have a table called tblschedule that has field for resourceID, employeeID, and scheduleDate. And also i have another table called tblResource that has resourceID and ResourceName. The third table called tblEmployee has employeeID, employeeFirstName and employeeLastname. I want to get a report for each resourceName (not ResourceID) that per employee schedule (COUNT). I need the report has ResourceName field, employeeName field and count. How can i write a store procedure as it need join three table to get the count. Thank you very much!Hello, i have a table called tblschedule that has field for resourceID, employeeID, and scheduleDate. And also i have another table called tblResource that has resourceID and ResourceName. The third table called tblEmployee has employeeID, employeeFirstName and employeeLastname. I want to get a report for each resourceName (not ResourceID) that per employee schedule (COUNT). I need the report has ResourceName field, employeeName field and count. How can i write a store procedure as it need join three table to get the count. Thank you very much!
assuming the tables are as follows,
tblEmployee
(
EmployeeID Int
EmployeeFirstName Varchar(50)
EmployeeLastName Varchar(50)
tblResource
(
ResourceID Int ,
ResourceName Varchar(50)
)
tblSchedule
(
ResourceID Int ,
EmployeeID Int ,
ScheduleDate DateTime
)
Try this and let me know if u have much refined version of this...
Select tE.EmployeeFirstName, tE.EmployeeLastName,tR.ResourceName,EmpCount.Sched ule
From tblEmployee tE
Inner Join tblSchedule tSE
On tE.EmployeeID = tSE.EmployeeID
Inner join tblResource tR
On tR.ResourceID = tSE.ResourceID
Inner Join (Select EmployeeID,Count(EmployeeID) As Schedule From tblSchedule Group By EmployeeID) EmpCount
On tE.EmployeeId = EmpCount.EmployeeID|||Thank you very much! But i have one more question, i would like to group the resourceID too. The result like:
Laptop John 12
Laptop smith 2
projector Rick 2
Cellphone Kim 2
Is it possible? Many thanks.
Thursday, March 8, 2012
aggregate in multiple table.
Labels:
aggregate,
database,
employeeid,
field,
microsoft,
multiple,
mysql,
oracle,
resourceid,
scheduledate,
server,
sql,
table,
tblschedule
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment