SQL question

5 pts.
Tags:
SQL
SQL tables
One table named as employee has 3 columns (name, salary, department). I need to retrieve the employees whose salary is greater than average salary of their department.

that is

name    salary   department

iioo      10000    Technical

aaaa    15000     HR

pppp    17000     HR

wwww    20000    Technical

 

I need to get employee details whose salary is greater than average salary of their department. kindly help me out



Software/Hardware used:
Sql server

Answer Wiki

Thanks. We'll let you know when a new response is added.

You’ll want something like this.

<pre>select *
from Employee
join (select Department, avg(Salary) Salary
FROM Employee
group by Department) a on Employee.Department = a.Department
and Employee.Salary > a.Salary</pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    We don't do homework here. Sorry.
    69,160 pointsBadges:
    report
  • Meandyou
    Hey - if you won't do my homework, how about some us my housework? :-)
    5,220 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following