Dispaly employee records who gets more salary than the average salary in their department?

Questions by kowmudiswarna   answers by kowmudiswarna

Showing Answers 1 - 48 of 48 Answers

Ashutosh Srivastava

  • Sep 21st, 2007
 

select * from emp a,
(select avg(sal) aa,deptno from emp group by deptno)x
where a.DEPTNO=x.deptno and a.sal>x.aa

Surender

  • Sep 22nd, 2007
 

select * from emp e where sal>(select avg(sal) from emp where deptno=e.deptno)

select b.ename, b.deptno, b.sal, avg_salfrom (select ename, deptno, avg(sal) over (partition by deptno) avg_sal, empno from emp) a, emp bwhere a.empno = b.empno and b.sal>a.avg_salorder by b.deptno;

  Was this answer useful?  Yes

  1  select employee_id,last_name,a.department_Id,salary,b.avg_sal   from employees a ,
  2  (select avg(salary) avg_sal,department_id from employees group by department_id) b
  3  where salary > (select avg(salary) from employees where department_id = a.department_id group by department_Id )
  4  and a.department_id = b.department_id
  5* order by a.department_Id
SQL> /

EMPLOYEE_ID LAST_NAME                 DEPARTMENT_ID     SALARY    AVG_SAL
----------- ------------------------- ------------- ---------- ----------
        201 Hartstein                            20      13000       9500
        124 Mourgos                              50       5800       3500
        103 Hunold                               60       9000       7400
        104 Ernst                                60       9000       7400
        149 Zlotkey                              80      10500 10033.3333
        174 Abel                                 80      11000 10033.3333
        100 King                                 90      24000 19333.3333
        205 Higgins                             110      12000      10150

8 rows selected.

  Was this answer useful?  Yes

Below is example query to get the employee details who gets the more than avg sal of their department.

select * from emp where salary > (select avg(salary) from emp a where a.deptno = emp.deptno group by deptno)

  Was this answer useful?  Yes

krishsidd

  • Nov 26th, 2010
 

1) select orderamount,salespersonid, row_number() over(order by orderamount
desc) rank from
(SELECT OrderAmount,SalesPersonID FROM orders order by orderamount desc) y where
rownum <= 5;


2) select orderamount,salespersonid, x rank from (SELECT
OrderAmount,SalesPersonID, rank() over(order by orderamount desc) x FROM orders)
y where x <=5;


3) select orderamount,salespersonid, x rank from (SELECT
OrderAmount,SalesPersonID, dense_rank() over(order by orderamount desc) x FROM
orders) y where x <=5;
For a,b - refer to 1
For c,d - can be done in 2 different ways as in 2 & 3


  Was this answer useful?  Yes

Nikhil

  • Oct 12th, 2011
 

Code
  1. SELECT sal FROM emp e,dept d

  2. WHERE e.depid=d.depid AND e.sal>(SELECT avg(e.sal) FROM emp e);

  Was this answer useful?  Yes

saikumar

  • Nov 2nd, 2011
 

select * from emp where sal>(select avg(sal) from emp);

may be this not correct

  Was this answer useful?  Yes

kranthi swaroop

  • Dec 3rd, 2011
 

Try this

Code
  1. SELECT ENAME,SAL

  2. WHERE SAL > (SELECT AVG(SAL)

  3.                          FROM EMP

  4.                          WHERE DEPTNAME ='COOK') -- Gets emp whose sal

  5.                                                                                 greater THAN Average sal

  6.                                                                                 FROM his department

  7. ORDER BY 2 ASC

  Was this answer useful?  Yes

uma

  • Mar 5th, 2012
 

select * from emp a
where salary >(select avg(salary) from emp b where a.dept_no = b.dept_no);

  Was this answer useful?  Yes

farhan

  • Apr 20th, 2012
 

Code
  1. SELECT * FROM emp  WHERE sal >(SELECT avg(sal) FROM emp)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions