The name and salary of the employee whose salary is above the average salary of the department

Source: Internet
Author: User


The name and salary of the employee whose salary is above the average salary of the department


Demolition: 1 The average salary of the department; 2 higher than the average employee's name and salary


1 average salary of the department

Select AVG (SAL) avgsal, deptno from EMP Group by DEPTNO;


2 names and salaries of employees above the departmental average salary

There needs to be a correlation query, which requires a comparison of the names of employees whose salaries are above the departmental average salary

Select A.ename, a.sal from
  emp A, (select AVG (SAL) avgsal, deptno to EMP Group by Deptno) b
 where a.sal > B.A Vgsal and
   a.deptno = B.deptno;


In order to facilitate the inspection of the above SQL query the accuracy of the results, we query to give the department number, convenient than the

Select A.ename, A.sal, A.deptno from
  emp A, (select AVG (SAL) avgsal, deptno to EMP Group by Deptno) b
 where a.sa L > B.avgsal and
   a.deptno = B.deptno;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.