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
Answers were Sorted based on User's Feedback
Answer / praveen
select * from emp e where sal<
(select avg(sal) from emp where deptno=e.deptno)
order by deptno
| Is This Answer Correct ? | 20 Yes | 2 No |
Answer / subbu
select e.eno,e.dno,e.sal
from emp_t e,
(select dno,avg(sal) avgsal from emp_t group by dno) b
where e.sal<b.avgsal and e.dno=b.dno
/
| Is This Answer Correct ? | 5 Yes | 4 No |
Answer / 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 |
Answer / madhu
select * from emp where sal<(select avg(sal) from emp where
eno in(2,3,4))
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mahalakshmi s
select * from (select id,(case when sal < avg(sal) over(partition by id) then sal else 0 end) avg_val from dept) a where avg_val !=0;
| Is This Answer Correct ? | 0 Yes | 0 No |
select department_id,salary from employees e
where salary<(select trunc(avg(salary))
from employees where department_id=e.department_id;
| Is This Answer Correct ? | 0 Yes | 0 No |
select salary from emp
wher dno in (select dno
from dept
where salary < any
(select avg(salary)
from dept
where dept = 3)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / prasant
select sal from demo where sal<(select avg(sal) from demo
where eno in (2,3,4));
NOTE:first create table demo and insert all these 5 rows
then run querry.
If any issue call me(PRASANT)
| Is This Answer Correct ? | 4 Yes | 5 No |
Answer / mohan
SELECT dno,sal
FROM EMP
WHERE sal>ANY(SELECT AVG(sal)
FROM emp
GROUP BY dno)
ORDER BY dno;
| Is This Answer Correct ? | 0 Yes | 2 No |
what are the advantages a stored procedure? : Sql dba
How do I remove duplicates in two columns?
What is the difference between clustered and non-clustered indexes?
What is an escape character in sql?
Do prepared statements prevent sql injection?
how to create a database in oracle?please gve anser with example
what is a trigger? : Sql dba
Where not exists in sql?
What are sql triggers used for?
what is constraining table?
what is self join and how it works??
What is the basic form of sql query?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)