0% found this document useful (0 votes)
26 views

Data-Base: Punjab University College of Information Technology

This document contains 15 tasks involving writing SQL queries to retrieve information from database tables for employees, departments, and salary grades. The queries select, join, and filter data from the tables to display employee names, departments, salaries, managers, and other attributes according to the specific conditions of each task. The tasks demonstrate basic and some advanced SQL skills for retrieving and organizing data from multiple database tables.

Uploaded by

Ahmad Nutt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Data-Base: Punjab University College of Information Technology

This document contains 15 tasks involving writing SQL queries to retrieve information from database tables for employees, departments, and salary grades. The queries select, join, and filter data from the tables to display employee names, departments, salaries, managers, and other attributes according to the specific conditions of each task. The tasks demonstrate basic and some advanced SQL skills for retrieving and organizing data from multiple database tables.

Uploaded by

Ahmad Nutt
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

2020

PUNJAB UNIVERSITY COLLEGE OF INFORMATION


TECHNOLOGY
LAB11

DATA-BASE
Prepared for Miss. Hareem Aslam
By. Talha Mazhar Bitf19a024
TASK 1

Write a query to display the name, department number, and department name for all employees.
SELECT e.ename, d.deptno, d.dname

FROM emp e

JOIN dept d

ON (e.deptno = d.deptno)

ORDER BY e.deptno;

TASK 2

Write a query to display the employee name, department name, location of all employees who earn a
commission
SELECT e.ename, d.dname, d.loc

FROM emp e, dept d

WHERE e.deptno = d.deptno


AND e.comm IS NOT NULL;

TASK 3

Write a query to display the name, job, department number, and department name for all employees who
work in Boston.
SELECT e.ename, e.job, e.deptno, d.dname, d.loc

FROM emp e

JOIN dept d

ON (e.deptno = d.deptno)

WHERE d.loc = 'BOSTON';

TASK 4
Display all employees along with their salgrade including King, who has no manager. Order the results by
the employee number.
SELECT ename, s.grade, s.losal, s.hisal

FROM emp e

FULL JOIN salgrade s

ON (e.sal = s.hisal)

Task 5

Create a query that displays the name, job, department name, salary, and grade for all employees.
SELECT e.ename, e.job, d.dname, e.sal, s.grade

FROM emp e

FULL JOIN dept d

ON e.deptno = d.deptno

FULL JOIN salgrade s

ON e.sal = s.hisal
TASK 6

Find out the emps who joined in the company before their Managers.
SELECT e.ename, e.hiredate, e1.ename, e1.hiredate

FROM emp e, emp e1

WHERE e.mgr = e1.empno

AND e.hiredate < e1.hiredate;


TASK 7

Create a query that displays employee names, salary, salary increased by 40% and their salary grade acc to
increased salary. Give each column an appropriate label.
SELECT e.ename, e.sal, e.sal + (e.sal * 0.4), s.grade

FROM emp e, salgrade s

WHERE e.sal + (e.sal * 0.4) BETWEEN s.losal AND s.hisal;


TASK 8

Display data of all the employees whose salgrade is 2.


SELECT *

FROM emp e, salgrade s

WHERE e.sal BETWEEN s.losal

AND

s.hisal

AND

s.grade = 2;
TASK 9

Create a query that displays employee names, department name of all the Employees who work in
department 10
SELECT e.ename, d.dname, d.deptno

FROM emp e, dept d

WHERE e.deptno = d.deptno

AND

d.deptno = 10;
TASK 10

Write a query to employee Name, Job, Annual Salary, deptno, Dept name and grade who earn 36000 or
more.
SELECT e.ename, e.job, e.sal*12, d.deptno, d.dname, s.grade

FROM emp e, dept d, salgrade s

WHERE e.deptno = d.deptno

AND

e.sal BETWEEN s.losal AND s.hisal

AND

e.sal*12 >= 36000;


TASK 11

List all the emps by name and number along with their Manager’s name and number. Also List KING who
has no ‘Manager’
SELECT e.ename, e.empno, ee.ename, e.empno

FROM emp e, emp ee

WHERE ee.empno(+) = e.mgr;


TASK 12

List the emps whose Mgr name is ‘Jones’ and also with his(Jones) Manager name.
SELECT e.ename, ee.ename

FROM emp e, emp ee

WHERE ee.empno = e.mgr

AND

ee.ename = 'JONES';
TASK 13

List all the employees who earn more than their managers.
SELECT e.ename, e.sal, ee.ename

FROM emp e, emp ee

WHERE ee.empno = e.mgr

AND

e.sal > ee.sal;

TASK 14
Write a query that display the salary grades of all employees that belongs to Accounting
Department.

SELECT e.ename, s.grade

FROM emp e, salgrade s, dept d

WHERE e.sal BETWEEN s.losal

AND

s.hisal

AND

d.dname = 'ACCOUNTING';

TASK 15

WRITE A QUERY THAT DISPLAYS ALL THE EMPLOYEES THAT HAVE SALARY GRADE OF 2 OR THEY
BELONG TO ‘BOSTON’.

SELECT *

FROM emp e, salgrade s, dept d

WHERE e.sal BETWEEN s.losal


AND

s.hisal

AND

s.grade = 2

AND

d.loc = 'BOSTON';

You might also like