0% found this document useful (0 votes)
42 views3 pages

Department of Computer Systems Engineering Mehran University of Engineering & Technology, Jamshoro Database Systems (4 Semester) 19CS Lab Experiments

This document contains instructions and solutions for 10 SQL queries on EMP and DEPT tables. The queries retrieve unique departments, employees hired between dates ordered by joining date, employees with two L's in their name in department 30 or with manager 7782, employees where commission is greater than salary increased by 10%, employees earning over 1500 in department 10 or 30, employees whose name starts and ends with specified letters, a query formatting employee name, salary and desired salary, employees whose job is clerk or analyst not earning specified salaries, employees where the third letter of their name is A, and employees earning commission ordered by salary and commission descending.

Uploaded by

AMMARA INAYAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Department of Computer Systems Engineering Mehran University of Engineering & Technology, Jamshoro Database Systems (4 Semester) 19CS Lab Experiments

This document contains instructions and solutions for 10 SQL queries on EMP and DEPT tables. The queries retrieve unique departments, employees hired between dates ordered by joining date, employees with two L's in their name in department 30 or with manager 7782, employees where commission is greater than salary increased by 10%, employees earning over 1500 in department 10 or 30, employees whose name starts and ends with specified letters, a query formatting employee name, salary and desired salary, employees whose job is clerk or analyst not earning specified salaries, employees where the third letter of their name is A, and employees earning commission ordered by salary and commission descending.

Uploaded by

AMMARA INAYAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1

DEPARTMENT OF COMPUTER SYSTEMS ENGINEERING


MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
Database Systems (4th Semester) 19CS
Lab Experiments

Consider following tables to write SQL queries.


EMP (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO )
DEPT (DEPTNO, DNAME, LOC)

Lab 4: To retrieve data from database using SQL SELECT Statement.


1. Create a query to display unique departments from EMP table.
Solution:

SELECT DISTINCT department_id

FROM hr.employees;

Output:

2. Display the employee name, job, and joining date of employees hired between February
20, 1981 and May 1, 1981. Order the query in ascending order by joining date.
Solution:
SELECT first_name ||' '||last_name "employee name", job_id, hire_date AS "Joining
date"

FROM hr.employees
WHERE hire_date BETWEEN '20-FEB-81' AND '01-MAY-81'

Output:

3. Display the names of all employees who have two ‘L’ in their name and are in
department 30 or their manager is 7782.
Solution:
SELECT first_name "employee name"

FROM hr.employees
WHERE (first_name like'%ll%' OR first_name like'%ll%') AND (manager_id=7782 OR
department_id=30);

Output:

4. Display the name, salary, and commission for all employees whose commission amount
is greater than their salary increased by 10%.
Solution:

ROLL NO: IMRAN ALI [19CS20]


2

SELECT first_name||''|| last_name "employee name", salary, commission_pct

FROM hr.employees
WHERE commission_pct>((salary*0.1)+salary);

Output:

5. Display the name and salary of employees who earn more than 1500 and are in
department 10 or 30. Label the columns Employee and Monthly Salary, respectively.
Solution:
SELECT first_name||''|| last_name "employee name", salary "Monthly Salary" ,
commission_pct

FROM hr.employees
WHERE salary>1500 AND department_id IN(10,30);*/

Output:

6. List out the employees whose name start with S and ends with H.
Solution:
SELECT first_name||' '|| last_name "employee name"
FROM hr.employees
WHERE first_name like 'S%' AND (first_name like '%H' OR last_name like '%H');

Output:

7. Write a query that produces following for each employee:


<employee name> earns <salary> monthly but wants <3 times salary>. Label the column Dream
Salaries.
Solution:
SELECT first_name||' '|| last_name || 'earns '|| salary ||' monthly but wants '|| (3*salary) as
"Dream Salary"
FROM hr.employees

Output:

8. Display the name job and salary for all employees whose job is clerk or analyst and their
salary is not equal to 1000, 3000, or 5000.
Solution:

ROLL NO: IMRAN ALI [19CS20]


3

SELECT job_id, salary


FROM hr.employees
WHERE (job_id like '%CLERK%' OR job_id like '%ANALYST%') AND salary NOT
IN(1000,3000,5000);

Output:

9. Display the names of all employees where the third letter of their name is an A.
Solution:
SELECT first_name

FROM hr.employees
WHERE first_name like '__A%';

Output:

10. Display name, salary and commission for all employees who earn commission. Sort the
result in descending order of salary and commission.
Solution:
SELECT first_name, salary, commission_pct
FROM hr.employees
WHERE commission_pct is not null
ORDER BY commission_pct desc, salary desc;

Output:

ROLL NO: IMRAN ALI [19CS20]

You might also like