Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

AGGREGATION:

============

These functions are also called as "Single Row Functions".

sum()
avg()
max()
min()
count() *****

SQL> select sum(sal),avg(sal),max(sal),min(sal),count(sal) from emp;

SUM(SAL) AVG(SAL) MAX(SAL) MIN(SAL) COUNT(SAL)


---------- ---------- ---------- ---------- ----------
29025 2073.21429 5000 800 14

waqtfo the avg salary of the emp table?

select avg(sal) from emp;

waqtfo the avg salary of the deptno 10?

select avg(sal) from emp where deptno = 10;

waqtfo the avg salary of the deptno where scott is working ?

select avg(sal) from emp where deptno = (select deptno from emp
where ename = 'SCOTT');

waqtfo the enames who is getting salary greater than all the employees of
deptno 10 or 20?

select ename
from emp
where sal > all (select sal from emp where deptno in (10,20));

select ename
from emp
where sal > (select max(sal) from emp where deptno in (10,20));

waqtfo the enames who is getting salary greater than any one of the employees of
deptno 10 or 20?

select ename
from emp
where sal > any (select sal from emp where deptno in (10,20));

select ename
from emp
where sal > (select min(sal) from emp where deptno in (10,20));
select ename
from emp
where sal > (select max(sal) from emp where job = 'CLERK')
and sal < (select min(sal) from emp where job = 'MANAGER' and deptno = 10);

waqtfo the overall avg salary of deptno 10 and 20?

select avg(sal)
from emp
where deptno = 10 or deptno = 20;

waqtfo the overall avg salary of deptno 10 and 20?

select avg(sal),deptno
from emp
where deptno = 10 or deptno = 20
group by deptno;

waqtfo the avg salary of each job designation?

select avg(sal)
from emp
group by job;

waqtfo the avg salary of CLERKS and MANAGER?

select job,avg(sal)
from emp
where job in ('CLERK','MANAGER')
group by job;

waqtfo the number of employess of CLERKS and MANAGER in deptno 10?

select count(ename),job
from emp
where job in ('CLERK','MANAGER') and deptno = 10
group by job;

select ename
from emp
where sal > all (select avg(sal) from emp where deptno in (10,20)
group by deptno);

select job,avg(sal)
from emp
where deptno in (select deptno from dept where loc = 'NEW YORk')
group by job;

select ename
from emp
where deptno in (select deptno from emp where ename = 'SMITH') and sal > all(select
avg(sal) from emp where job in ('CLERK','MANAGER') group by job);

HAVING:
======

You might also like