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

assignment 4

Assignment

Uploaded by

Tarik Nadeem
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)
2 views

assignment 4

Assignment

Uploaded by

Tarik Nadeem
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/ 6

DBMS Lab 09-10-2020

Assignment 3

Q1 to Q3 will use the following 3 tables:

Worker table:

Name Data Type Constraint Size

Worker_ID Number Primary Key


First_Name Varchar2 Not null 25
Last_Name Number Not null 25
Salary Number Not null 15
Joining_Date Date Not null
Department Varchar2 Not null 25

Worker_ID First_Name Last_Name Salary Joining_Date Department


001 Monika Arora 100000 19-feb-20 HR
002 Niharika Verma 80000 14-jun-11 Admin
003 Vishal Singhal 300000 27-feb-20 HR
004 Amitabh Singh 500000 7-feb-11 Admin
005 Vivek Bhati 50000 14-jun-11 Admin
006 Vipul Diwan 200000 14-jun-11 Account
007 Satish Kumar 75000 14-jan-20 Account
008 Geetika Chauhan 90000 14-apr-11 Admin
Bonus table:

Name Data Type Constraint Size

Worker_Ref_ID Number Foreign Key*


Bonus_amount Number Not null 10
Bonus_date Date
*Worker_Ref_ID is Foreign Key with reference to Worker_ID of Worker Table
Worker_Ref_ID Bonus_amount Bonus_date
001 5000 16-mar-20
002 3000 16-jun-11
003 4000 16-mar-20
001 4500 16-mar-20
002 3500 16-jun-11

Title table:

Name Data Type Constraint Size

Worker_Ref_ID Number Foreign Key*


Worker_title Varchar2 Not null 25
Affected_from Date
*Worker_Ref_ID is Foreign Key with reference to Worker_ID of Worker Table

Worker_Ref_ID Worker_title Affected_from


001 Manager 20-feb-20
002 Executive 16-jun-11
008 Executive 16-jun-11
005 Manager 16-jun-11
004 Asst. Manager 16-jun-11
007 Executive 16-jun-20
006 Lead 16-jun-11
003 Lead 16-jun-20
1. Write sql queries for below questions:
a. Write an SQL query to print details of the Workers whose FIRST_NAME ends
with ‘h’ and contains six alphabets.
b. Write an SQL query to print the FIRST_NAME from Worker table after
replacing ‘a’ with ‘A’.
c. Write an SQL query to print details for Workers with the first name as “Vipul”
and “Satish” from Worker table.
d. Write an SQL query to print details of workers excluding first names, “Vipul”
and “Satish” from Worker table.
e. Write an SQL query to fetch departments along with the total salaries paid for
each of them.

2. Write sql queries:


a. Write an SQL query to show only odd rows from a table.
b. Write an SQL query to show only even rows from a table.
c. Write an SQL query to show the second highest salary from worker table.
d. Write an SQL query to fetch the first 50% records from a table.
e. Write an SQL query to fetch the departments that have less than five people
in it.

3. Write sql queries:


a. Write an SQL query to show the last record from a table.
b. Write an SQL query to fetch the first row of a table.
c. Write an SQL query to fetch the names of workers who earn the highest
salary.
d. Write an SQL query to fetch the no. of workers for each department in the
descending order.
e. Write an SQL query to fetch worker names with salaries >= 50000 and <=
100000.
Q4 to Q6 will use the following 3 tables:

Department table:

Name Data Type Constraint Size

Dep_id Number Primary Key


Dep_name Varchar2 20
Dep_location Varchar2 15

Dep_id Dep_name Dep_location


1001 Finance Sydney
2001 Audit Melbourne
3001 Marketing Perth
4001 Production Brisbane

Salary_grade table:

Name Data Type Constraint

Grade Number Primary Key


Min_salary Number
Max_salary Number

Grade Min_salary Max_salary


1 800 1300
2 1301 1500
3 1501 2100
4 2101 3100
5 3101 9999
Employees table:

Name Data Type Constraint Size

Emp_id Number Primary Key


Emp_name Varchar2 15
Job_name Varchar2 10
Manager_id Number
Hire_date Date
Salary Number 10,2
Commission Number 7,2
Dep_id Number Foreign Key*
*Dep_id is Foreign Key with reference to Dep_id of department table.

Emp_id Emp_name Job_name Manager_id Hire_date Salary Commission Dep_id

68319 Kayling President 18-11-91 6000.00 1001


66928 Blaze Manager 68319 01-05-91 2750.00 3001

67832 Clare Manager 68319 09-06-91 2550.00 1001


65646 Jonas Manager 68319 02-04-91 2957.00 2001
67858 Scarlet Analyst 65646 19-04-97 3100.00 2001
69062 Frank Analyst 65646 03-12-91 3100.00 2001
63679 Sandrine Clerk 69062 18-12-90 900.00 2001
64989 Adelyn Salesman 66928 20-02-91 1700.00 400.00 3001
65271 Wade Salesman 66928 22-02-91 1350.00 600.00 3001
66564 Madden Salesman 66928 28-09-91 1350.00 1500.00 3001
68454 Tucker Salesman 66928 08-09-91 1600.00 0.00 3001
68736 Adnres Clerk 67858 23-05-97 1200.00 2001
69000 Julius Clerk 66928 03-12-91 1050.00 3001
69324 Marker Clerk 67832 23-01-92 1400.00 1001
4. Write sql queries
a. Write a query to count the no. of characters without considering the spaces
for each employee name.
b. List all the employees who joined before 1991.
c. List the name of employees and their manager separated by the string ‘works
for’. For example, Blaze works for Kayling.
d. List the employee name and job_name who are not working under a
manager.
e. List employee id, name along with department name.

5. Solve the below questions


a. List the name, job name, manager id, salary, manager name, manager’s salary
for those employees whose salary is greater than the salary of their managers.
b. List the employees name, department, salary and commission. For those
whose salary is between 2000 and 5000 while location is PERTH.
c. List the employees who are working either MANAGER or ANALYST with a
salary range between 2000 to 5000 without any commission.
d. List the employees who are senior to their own managers (those employees
who were hired before their managers).
e. List the id, name, monthly salary, daily salary of all the employees in the
ascending order of their annual salary.

6. Solve the queries:


a. Write a query to display the location of CLARE.
b. List the employees in ascending order of the salary whose annual salary is
below 25000.
c. Display the number of employees for each job in each department.
d. List total number of managers and clerks.
e. Calculate minimum, maximum, average and total salary from employees
table.

You might also like