Database All Queries of MID TERM
Database All Queries of MID TERM
By:
SADAT JUBAYER
Lab Performance 01
1. Create a query to display the name and salary of employees earning more than $2850.
2. Create a query to display the employee name and department number for employee number 7566.
3. Display the employee name, job, and start date of employees hired between February
20, 1981, and May 1, 1981. Order the query in ascending order by start date.
SELECT ename,job,hiredate FROM emp WHERE hiredate BETWEEN '20-FEB-81' AND '1-MAY-81' ORDER BY
hiredate;
4. Display the employee name and department number of all employees in departments
10 and 30 in alphabetical order by name.
5. Display the name and hire date of every employee who was hired in 1982.
6. Display the name and job title of all employees who do not have a manager.
7. Display the name, salary, and commission for all employees who earn commissions. Sort data in descending
order of salary.
SELECT ename,sal,comm FROM emp WHERE comm IS NOT NULL ORDER BY sal;
8. Display the names of all employees where the third letter of their name is an A.
9. Display the name of all employees who have two Ls in their name.
SELECT ename FROM emp WHERE ename LIKE '%L%L%';
10. Display the losal and hisal columns from the salgrade table.
SELECT losal,hisal FROM salgrade;
AIUB COURSE SOLUTION
Lab Performance 02
1. Display the employee number, hiredate and number of months Blake has worked.
3. Display the employee number, hiredate and rounded hiredate to month. Use the round function.
4. Display the employee number, hiredate and truncated hiredate to month. Use the trunc function.
5. Manipulate the salary of employee Blake in such a way that it is displayed as $002,850.
6. Display the hiredate of all employees in the format DD-MONTH-YEAR(e.g 17 December Nineteen
Eighty).
8. Display all the data of commission column in such a way that if there is any null value in this column it
will be replaced by the string ‘No Commission Yet’.
SELECT NVL(TO_CHAR(COMM),'No Comission Yet') FROM emp;
9. Check if the values of column ename and job are equal using nullif function.
10. Manipulate the data of comm column of emp table in such way that if data is null it will display NULL
and if data is not null it will display not null.
11. Display the incremented salary of salesman by $2000, manager by $3000 and president by $4000.
Salaries of other employee will not increase. Use decode function.
13. Display the employee name and department number by joining the columns using concatenation
function.
14. Calculate and display the rounded salary of employee King and Ford after dividing salary by 300.
15. Calculate and display the remainder of the ratio of salary to commission for all employees whose job
title is salesman.
Lab Performance 03
1. Find the average, minimum and maximum salary of the employees. Label the columns AVG, MIN and MAX
respectively.
2. Modify your previous query to find the average, minimum and maximum salary of employees according to
department number.
SELECT deptno,AVG(sal) "AVG", MIN(sal) "MIN", MAX(sal) "MAX" FROM emp GROUP BY deptno;
3. Modify your previous query to find the average, minimum and maximum salary of employees according to job
category.
SELECT job,AVG(sal) "AVG", MIN(sal) "MIN", MAX(sal) "MAX" FROM emp GROUP BY job;
4. Display the department number and minimum salary grouped by department number but make sure the
minimum salary is greater than $800.
8. Display the sum of salaries grouped by the department number and job but the sum of salary must be greater
than 5000.
7. Display the name, salary and revised Salary. If manager ID is 7902 revised salary will be actual
salary+100, if manager ID is 7788 revised salary will be actual salary+200. For others the revised salary
will be actual salary+60. Sort by descending order of revised salary.
8. Display the truncated average remainder of the ratio of losal to hisal considering also the null values.
Rename the column Remainder.
9. Display the employee number, employee name, job, salary and start date of employees whose salary is
between 1000 and 2000. Order the query in ascending order by salary.
SELECT empno, ename,job,sal,hiredate FROM emp WHERE sal BETWEEN 1000 AND 2000 ORDER BY
SAL;
10. Display the name and job of all employees who have the letters ‘ERK’ or ‘LES’ in their designation.
Make sure there is no other letters in between the said letters.
SELECT ename, job FROM emp WHERE job LIKE '%ERK%' OR job LIKE '%LES%';