Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help to write the query?

Author  Topic 

davidsong
Starting Member

6 Posts

Posted - 2007-04-12 : 02:03:39
Hi all,

I have two tables, EMPLOYEE_TBL and EMPLOYEESTAR_TBL, the first table stores all the employees infomation and the other table stores the poll items for every employee.
Now I want to query all the employees and the avg poll qualtity into one view. That is I want output the data just like:

employeeName, employeeEmail, employeeStarsNumberAVGValue ...

How to do it? Thanks you very much.

David

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-12 : 02:07:31
[code]
select e.employeeName, e.employeeEmail, employeeStarsNumberAVGValue = avg(somecol)
from EMPLOYEE_TBL e inner join EMPLOYEESTAR_TBL s
group by e.employeeName, e.employeeEmail
[/code]


KH

Go to Top of Page

davidsong
Starting Member

6 Posts

Posted - 2007-04-12 : 02:20:26
Thanks a lot to khtan

I wrote the query like above you wrote,

select e.empname, e.empemail,stars = avg(s.startnum)
from EMPLOYEE_TBL e inner join EMPSTARS_TBL s
group by e.empname, e.empemail

error occored: Error Executing Database Query.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-12 : 02:21:52
where & how do you execute the query ? in SQL Server Management Studio ?


KH

Go to Top of Page

davidsong
Starting Member

6 Posts

Posted - 2007-04-12 : 02:24:28
I execute the it in Access 2007
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-12 : 02:26:46
try this


select e.employeeName, e.employeeEmail, avg(somecol) as employeeStarsNumberAVGValue
from EMPLOYEE_TBL e inner join EMPLOYEESTAR_TBL s
group by e.employeeName, e.employeeEmail


BTW, this is a SQL Server 2005 forum. For Ms Access, please post at http://www.sqlteam.com/forums/forum.asp?FORUM_ID=3


KH

Go to Top of Page

davidsong
Starting Member

6 Posts

Posted - 2007-04-12 : 02:30:44
It does work. Thank you very much!
Go to Top of Page
   

- Advertisement -