i have a table
eno dno sal
1 10 200
2 10 150
3 10 100
4 20 75
5 20 100

i want to get sal which is less than the avg sal of thri dept.

eno dno sal
2 10 150
3 10 100
4 20 75

Answer Posted / biswa

select *
from (select eno,dno,sal,avg(sal) over(partition by dno) as
avg_sal
from emp)
where sal<avg_sal;

OR

select e1.empno,e1.deptno,e1.sal
from emp e1
where sal>(select avg(sal) from emp e2
where e1.deptno=e2.deptno)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is rollback?

579


Can we create table inside stored procedure?

532


What is a database trigger?

612


Is record in pl sql?

513


How many types of tables are there?

503






Does truncate remove indexes?

559


Why we use stored procedure instead of query?

533


hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews

1523


Should I use mbr or gpt?

542


how can we take a backup of a mysql table and how can we restore it. ? : Sql dba

517


What are the sql aggregate functions?

602


Which kind of parameters cannot have a default value in pl sql?

593


What are dml commands?

524


What is the difference between clustered and non-clustered indexes?

601


tell us something about heap tables. : Sql dba

596