Database: Task 1

You might also like

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

DATABASE

TASK 1:
Display records of all the employees having salary more than 1000 and they earn commission.

QUERY:

SELECT * FROM EMP


WHERE SAL > 1000
AND (COMM IS NOT NULL
AND COMM != 0);
TASK 2:
Show department number and location of accounting and sales department.

QUERY:

SELECT DEPTNO, LOC FROM DEPT


WHERE DNAME = 'ACCOUNTING' OR DNAME = 'SALES';

TASK 3:
Display name and salary for all employees whose salary is not in the range of 1500 and 2850.

QUERY:

SELECT ENAME, SAL FROM EMP


WHERE SAL NOT BETWEEN 1500 AND 2850;

TASK 4:
Display data of all the employees having “C” in their name.

QUERY:

SELECT * FROM EMP


WHERE ENAME LIKE '%C%';

TASK 5:
Display the name, job title and the department of all employees who do not have a manager.

QUERY:

SELECT ENAME, JOB, DEPTNO FROM EMP


WHERE MGR IS NULL;

TASK 6:
Display job title and hire date of employees having commission less than 300. (Note: Commission can be
null)

QUERY:

SELECT JOB, HIREDATE FROM EMP


WHERE COMM < 300
OR COMM IS NULL;

TASK 7:
Display record of all employees who work in department no 10 with dept no appearing as a first column.

QUERY:

SELECT DEPTNO, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM FROM EMP
WHERE DEPTNO = 10;

TASK 8:
Display data of all those employees whose name start with T and ends with R.

QUERY:

SELECT * FROM EMP


WHERE ENAME LIKE 'T%'
AND ENAME LIKE '%R';
TASK 9:
Display the employee name, salary and employee number whose Mgr no is between 7300 and 7800.

QUERY:

SELECT ENAME, SAL, EMPNO FROM EMP


WHERE MGR BETWEEN 7300 AND 7800;

TASK 10:
Display the record of all the employees who do not earn commission.

QUERY:

SELECT * FROM EMP

WHERE COMM = 0

OR COMM IS NULL;
TASK 11:
Write a query that display the employees that have commission greater than 20% of their salary

QUERY:

SELECT * FROM EMP


WHERE COMM > (0.20 * SAL);

TASK 12:
Sort all the employees according to their department number and if department number is same then
according to their hiredate.

QUERY:

SELECT * FROM EMP


ORDER BY DEPTNO, HIREDATE ASC;

TASK 13:
Display Name, department number and salary of all the employees. Sort data according to their salary
from maximum to minimum. (Note: You are not allowed to use column name in condition).

QUERY:
SELECT ENAME, DEPTNO, SAL FROM EMP
ORDER BY 3 DESC;
TASK 14:
Display record of employees whose salary is 3000 or 5000 (Note: You are not allowed to use equal
operator)

QUERY:

SELECT * FROM EMP


WHERE SAL IN (3000,5000);

TASK 15:
Display the employee name and department number of all employees in departments 10 and 30 in
alphabetical order by name

QUERY:

SELECT ENAME, DEPTNO FROM EMP


WHERE DEPTNO IN (10,30)
ORDER BY ENAME ASC;

You might also like