0% found this document useful (0 votes)
47 views

SQL Group Function

This document provides examples of using SQL group functions such as MAX, MIN, SUM, AVG, and COUNT to aggregate data from the EMP table. The examples group and calculate statistics by JOB, DEPTNO, and SAL columns to get the highest, lowest, total, average salaries as well as counts of distinct jobs and salaries.

Uploaded by

Ashish Manchekar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

SQL Group Function

This document provides examples of using SQL group functions such as MAX, MIN, SUM, AVG, and COUNT to aggregate data from the EMP table. The examples group and calculate statistics by JOB, DEPTNO, and SAL columns to get the highest, lowest, total, average salaries as well as counts of distinct jobs and salaries.

Uploaded by

Ashish Manchekar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL GROUP FUNCTION

1. SELECT MAX(SAL), MIN(SAL), SUM(SAL), ROUND(AVG(SAL),0) AVERAGE FROM EMP;


2. SELECT JOB, MAX(SAL), MIN(SAL), SUM(SAL), ROUND(AVG(SAL),0) AVERAGE FROM EMP
GROUP BY JOB;
3. SELECT JOB, COUNT(JOB) FROM EMP GROUP BY JOB ;
4. SELECT JOB, COUNT(JOB) FROM EMP WHERE JOB='MANAGER' GROUP BY JOB;
5. SELECT (MAX(SAL)- MIN(SAL)) DIFFERENCE FROM EMP;
6. SELECT DEPTNO, (MAX(SAL)-MIN(SAL)) DIFFERENCE_SALARY FROM EMP GROUP BY DEPTNO;
7. SELECT DEPTNO, AVG(SAL) FROM EMP WHERE HIREDATE>'01-07-1983' GROUP BY DEPTNO;
8. SELECT;
9. SELECT;
10. SELECT ENAME, JOB, MIN(SAL) FROM EMP WHERE JOB='MANAGER' AND SAL>1000 GROUP
BY ENAME, JOB;
11. SELECT JOB, COUNT(JOB), ROUND(AVG(SAL),2) FROM EMP GROUP BY JOB;
12. SELECT SAL, COUNT(DISTINCT(SAL)) FROM EMP GROUP BY SAL;

You might also like