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
 Other Forums
 Other Topics
 SQL querie

Author  Topic 

jimmy_t85
Starting Member

1 Post

Posted - 2009-03-14 : 01:03:39
Hello,
First up i know i am only new, and i did dislike it on other forums where newbies would come straight on and ask questions. So please don't bite my head off.
I am studying at University and one of my subjects is on an introduction to databases. Not overly technical just enough to get us through.
I have trawled the net trying to find an answer to my question and my text however i can't seen to find an answer.
The question is how may staff have a salary greater than the average salary?
Staff table consists of staffNo, fName, lName, position, sex, DOB, salary, branchNo

I originally tried
SELECT COUNT (staffNo)
FROM Staff
WHERE salary > AVG (salary)

however this returns a result so i tried the above the same again but WHERE salary > SELECT AVG (salary)
FROM Staff
this still outputs an error.
Ive tried on google but most stuff ive found relates to only SELECT FROM GROUB BY, WHERE clauses. Or embeding sql queries in code.
Thankyou in advance.
I don't mind if you just point me in the right direction instead of an answer as the more work i do the better ill get at this stuff.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-12 : 10:01:26
WHERE salary > (select AVG (salary) from staff)




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -