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
 General SQL Server Forums
 New to SQL Server Programming
 yet another problem

Author  Topic 

ghostfly
Starting Member

6 Posts

Posted - 2011-02-15 : 12:44:40
Trying to display first name, lastname, departmentname and salary of those personnel who's salary is above the average.

SELECT e.Firstname, e.LastName, e.salary, d.departmentname as Employee , 
avg(e.salary) as salaries
FROM Employeesf e
right join departments d on e.departmentid = d.departmentid
--where e.salary > avg(salaries)
group by e.firstname, e.lastname, e.salary, d.departmentname


error:An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-15 : 13:28:38
SELECT e.Firstname, e.LastName, e.salary, d.departmentname as Employee
FROM Employeesf e
right join departments d on e.departmentid = d.departmentid
where e.Salary>(select avg(salary) from Employeesf)
Go to Top of Page

ghostfly
Starting Member

6 Posts

Posted - 2011-02-15 : 15:13:40
ty -- so basically i had all the stuff but in the wrong order--except for your additional select
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-15 : 15:25:30
somehow
Go to Top of Page
   

- Advertisement -