Subqueries with Aggregate function
Subqueries with Aggregate function
SELECT
* FROM XXSD_EMP_TL
EMPNO
|
ENAME
|
JOB
|
MGR
|
SAL
|
COMM
|
DEPTNO
|
7369
|
SMITH
|
CLERK
|
7902
|
800
|
|
20
|
7499
|
ALLEN
|
SALESMAN
|
7698
|
1600
|
300
|
30
|
7521
|
WARD
|
SALESMAN
|
7698
|
1250
|
500
|
30
|
7566
|
JONES
|
MANAGER
|
7839
|
2975
|
|
20
|
7654
|
MARTIN
|
SALESMAN
|
7698
|
1250
|
1400
|
30
|
7698
|
BLAKE
|
MANAGER
|
7839
|
2850
|
|
30
|
7782
|
CLARK
|
MANAGER
|
7839
|
2450
|
|
10
|
7788
|
SCOTT
|
ANALYST
|
7566
|
3000
|
|
20
|
7839
|
KING
|
PRESIDENT
|
|
5000
|
|
10
|
7844
|
TURNER
|
SALESMAN
|
7698
|
1500
|
0
|
30
|
7876
|
ADAMS
|
CLERK
|
7788
|
1100
|
|
20
|
7900
|
JAMES
|
CLERK
|
7698
|
950
|
|
30
|
7902
|
FORD
|
ANALYST
|
7566
|
3000
|
|
20
|
7934
|
MILLER
|
CLERK
|
7782
|
1300
|
|
10
|
--====================================================
Aggregate Function :- Max / Min / Avg / Sum / Count
--====================================================
select
MAX(SAL) , MIN(SAL), AVG(SAL), SUM(SAL), COUNT(SAL)
from XXSD_EMP_TL
MAX(SAL)
|
MIN(SAL)
|
AVG(SAL)
|
SUM(SAL)
|
COUNT(SAL)
|
12000
|
800
|
3351.785714
|
46925
|
14
|
--====================================================
--if any one ask regarding max / min
salary
--====================================================
select
MAX(SAL) from xxsd_emp_tl
5000
--====================================================
-- if i want to know about the employee
info who gets this salary
--====================================================
select
* from xxsd_emp_tl
where
sal = 5000 -- ( it provides
always static info )
select
MAX(SAL) from xxsd_emp_tl
select
* from xxsd_emp_tl
where
sal = ( select MAX(SAL) from xxsd_emp_tl )
-- ( it provides always static info )
edit xxsd_emp_tl
Comments
Post a Comment