0% found this document useful (0 votes)
3 views4 pages

Assignment 3

The document contains SQL queries related to employee data management, including operations like replacing characters in strings, handling NULL values, counting employees by job title, and calculating salaries. It also includes queries for finding minimum and maximum salaries, as well as aggregating data by departments and job categories. Overall, it provides a comprehensive set of examples for managing and analyzing employee information in a database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Assignment 3

The document contains SQL queries related to employee data management, including operations like replacing characters in strings, handling NULL values, counting employees by job title, and calculating salaries. It also includes queries for finding minimum and maximum salaries, as well as aggregating data by departments and job categories. Overall, it provides a comprehensive set of examples for managing and analyzing employee information in a database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment-3

1. Replace all ‘A’s from ‘MALAYALAM’ by E

SELECT REPLACE('MALAYALAM','A','E') FROM DUAL

RE PL ACE (' M AL AY AL AM', ' A', 'E ')


MELEYELEM

2. Display 0 for all employees whose commission is NULL

select NVL(COMM,0) from emp;

NV L(C OM M, 0)
0
300
500
0
1400
0
0
0
0
0

3. Find total number of clerks working in the company.

select COUNT(job)
from emp
where job='CLERK';

C OU NT (JOB)
4

4. Find total number of clerks who joined after 01-Jan-81.

select COUNT(job)
from emp
where job='CLERK' and hiredate>'01-JAN-81';

SELECT 12*(SAL+NVL(COMM,0)) FROM emp WHERE JOB = 'MANAGER'

C OU NT (JOB)
3

5) Find the number of employees working under different departments

select deptno,COUNT(ename) from emp


group by deptno

DE PT N O C OU NT (E N AME )
30 6
20 5
10 3

6. Find the overall total of basis salary and commission for all employees.

select SUM(sal),SUM(comm) from emp

S UM (S AL) S UM (C OM M)
29025 2200

7. Find the yearly compensation paid to all managers.

SELECT ename,12*(SAL+NVL(COMM,0)) as compensation FROM emp WHERE JOB = 'MANAGER'

E N AME C OMPE NS AT I ON
JONES 35700
BLAKE 34200
CLARK 29400

8. Find the average salary of all salesmen.

select AVG(sal) from emp where job='SALESMAN'

AV G (S AL)
1400

9. Who comes first in the alphabetical order of appearance?

select MIN(ename) from emp

M IN(E N AME )
ADAMS

10. Find the maximum salary of the employees in various departments, job-wise.

select job,deptno,max(sal) from emp group by job,deptno;

J OB DE PT N O M AX (S AL)
MANAGER 20 2975
PRESIDENT 10 5000
CLERK 10 1300
SALESMAN 30 1600
ANALYST 20 3000
MANAGER 30 2850
MANAGER 10 2450
CLERK 30 950
CLERK 20 1100

11. Find the minimum and maximum salary of all managers in all departments.

select job,min(sal),max(sal) from emp group by job having job='MANAGER'

J OB M IN(S AL) M AX (S AL)


MANAGER 2450 2975

12. Find the minimum salary of all managers in the departments where the minimum salary is above
Rs. 2500.

select deptno,job,min(sal) from emp group by job,deptno having job='MANAGER' and min(sal)>2500

DE PT N O J OB M IN(S AL)
20 MANAGER 2975
30 MANAGER 2850

13. Find the minimum salary and job of various categories of employees.

select job,min(sal) from emp group by job

J OB M IN(S AL)
CLERK 800
SALESMAN 1250
PRESIDENT 5000
MANAGER 2450
ANALYST 3000

14. List the maximum salary of employees department wise and display only those departments
whose maximum salary is greater than 1500.

select deptno,max(sal) from emp group by deptno having max(sal)>1500

DE PT N O M AX (S AL)
30 2850
20 3000
10 5000

15. List the various categories of employees and their departments such that the maximum salary is
greater than 1500.

select job,deptno,max(sal) from emp group by job,deptno having max(sal)>1500


J OB DE PT N O M AX (S AL)
MANAGER 20 2975
PRESIDENT 10 5000
SALESMAN 30 1600
ANALYST 20 3000
MANAGER 30 2850
MANAGER 10 2450

16. Write queries to differentiate between COUNT (*), COUNT (expr) and COUNT (distinct).

select count(*),count(sal),count(distinct sal) from emp

C OU NT (*) C OU NT (S AL ) C OU NT (DIS T INCT S AL)


14 14 12

10.*
select max(sal) from emp group by job;

M AX (S AL)
1300
1600
5000
2975
3000

You might also like