DBMS Assignment(Week 8)

You might also like

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

DBMS Assignment(Week 8)

Sorts, Groups, and Aggregates:

Display the list of employees sorted by DEPTNO in ascending order and by SAL in
descending order.

SELECT * FROM EMP SORT DEPTNO ASC AND SAL DESC;

Display the number of employees in each department.

SELECT DEPTNO, COUNT(ENAME) FROM EMP GROUP BY DEPTNO;

Display the number of employees by department (displaying by department its number and
name).

SELECT DEPTNO, DNAME, COUNT(EMP) FROM EMP GROUP BY DEPTNO;

Display the average salary by department, taking commissions into account.

SELECT DEPTNO, AVG(SAL + NVL(COMM 0)) AS AVG_SAL FROM EMP GROUP BY DEPTNO;

Display the average of non-zero commissions by job title.

SELECT JOB, AVG( COMM) AS AVG_COMM FROM EMP WHERE COMM IS NOT NULL AND
COMM != 0 GROUP BY JOB;

Display the total salaries of employees who have the same direct superior as "BLAKE".

SELECT SUM(SAL) AS TOTAL_SAL FROM EMP WHERE MNG = (SELECT EMPNO FROM EMP
WHERE UPPER(last_name) = 'BLAKE');

Display the list of department numbers sorted by the number of employees.

SELECT DEPTNO, COUNT(*) AS NO_OF_EMP FROM EMP GROUP BY DEPTNO ORDER BY


NO_OF_EMP DESC;

You might also like