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

Suppose you want to build up your own startup company.

That’s why you hired some


workers for your company. To ensure proper management of their data you need to
maintain a database system. As a computer science engineering student your job is to
create a relational database for your company from the requirements specified below:

RDBMS- Oracle 10g Language-SQL

First log in your system. You have the opportunity of unlimited table space. You have the
permission to create tables. After logging in with your username and password first create
two tables i.e. Worker and Bonus. Worker table has six columns containing information
about Workers Identification Number, First_Name, Last_Name, Department, Joining Date,
Salary. Bonus table has three columns containing information about Workers ref Id, Date
and Amount. Here W_Id is the primary key columns of worker and Worker_ref_Id is the
foreign key of the bonus table. The two tables along with their inserted data are given
below:

Table: Worker

W_Id First_Name Last_Name Department Joining Date Salary

1 Harry Porter HR 1/3/2016 150000


2 Monica Teres Account 14/3/2019 55000
3 Hannah Muri Admin 22/4/2020 85000
4 Cedric Leo HR 7/1/2020 75000
5 Cho Len Null 25/9/2006 200000
6 Luna Costa Admin 1/1/2021 150000
7 Draco Borna HR 3/5/2021 80000
8 pask Sijer Account 1/1/2020 45000
9 Goyle Firzo HR 4/5/2021 85000

Table:Bonus
Worker Ref Bonus Date Bonus Amount
_Id

2 20-3-2020 5000
1 9-8-2021 7000
1 7-5-2021 9000
3 7-2-2021 8500
After creating the tables and inserting data based on provided requirements write Queries
(Write down the question and also the answer) according to the following specification:

-using ARITHMETIC operator

1.Write an SQL query where bonus amount -using IS NULL operator


will be increasing into double and column
name will be double bonus. 5.Write an SQL query to find the name of the
Ans: Select bonus_ammount, worker who’s department value is null
2*bonus_ammount AS double bonus Ans: SELECT FIRST_NAME, DEPARTMENT
from bonus; FROM worker WHERE DEPARTMENT IS NULL;

-using CONCATENATION operator


-using ORDER BY
2.Write an SQL query to print the
6.Write an SQL query to show the salary of
FIRST_NAME and LAST_NAME from Worker
the workers in the descending order.
table into a single column COMPLETE_NAME.
Ans: SELECT salary FROM worker
A space char should separate them
ORDER BY salary DESC;
Ans: Select CONCAT(FIRST_NAME, ' ',
LAST_NAME) AS 'COMPLETE_NAME' from
Worker;

-using COLUMN ALIAS


-using SUBSTR function
3.Write an SQL query to show the Annual
7.Write an SQL query to print the first three
salary of the workers
characters of  FIRST_NAME from Worker
Ans: SELECT FIRST_NAME, salary*12 annsal
table.
FROM worker
Ans: Select substring(FIRST_NAME,1,3) from
ORDER BY annsal;
Worker;

-using NVL function


-using LIKE operator
8.Write an SQL query where if an worker has
4.Write an SQL query to print details of been not assigned to any department yet
Workers with DEPARTMENT name as department is NULL(n/a). Otherwise it will
“Admin” display the actual department name.)
Ans: Select * from Worker where Ans: SELECT first_name,
DEPARTMENT like 'Admin%'; NVL(Department,'n/a')
FROM workers;
-using MAX function
14.-using MULTIPLE-ROW subquery 
9.Write an SQL query to show the second
highest salary from worker table. Write an SQL query to show worker’s
Ans: Select max(Salary) from Worker First_names with salaries >= 50000 and <=
where Salary not in (Select max(Salary) from 100000.
Worker); Ans: SELECT FIRST_NAME, Salary
FROM worker WHERE W_ID IN
-using SUM function (SELECT W_ID FROM worker
WHERE Salary BETWEEN 50000 AND
10.Write an SQL query to show the total 100000);
salary of the workers
Ans: Select SUM(salary) from worker;
From employee; -using EQUIJOIN

15.Write an sql query which can join worker


-using GROUP BY clause
id, fetch worker names form worker table
and worker’s reference id, bonus amount
11.Write an SQL query to show the average
from bonus table.
salary of the specific grouped department
Ans: SELECT worker.w_id,
Ans: SELECT Department, AVG(salary)
worker.CONCAT(First_name, ' ', Last_Name)
FROM worker
As Worker_Name,bonus.Worker Ref_Id,
GROUP BY Department;
bonus.bonus amount from worker,bonus
where w_id= Worker Ref _Id;
-using HAVING clause

12.Write an SQL query to show the -using SIMPLE VIEW


maximum salary of the specific grouped
department which is more than 75000 T.k) 16.Create a view, worker information, that
Ans: SELECT deptno, max(sal) contains details of worker’s in department
FROM emp HR.
GROUP BY deptno CREATE VIEW workers_info
HAVING max(salary)>75000; AS
SELECT W_id, First_Name, Last_name,
department, joining date
13.-using SINGLE-ROW subquery  FROM Worker
Where department = ‘HR’;
Write an SQL query to to fetch worker
names,department and minimum salary -using COMPLEX VIEW 
from the worker table.
SELECT CONCAT(FIRST_NAME, ' ', 17.Write an sql query which creates a view
LAST_NAME) As Worker_Name, that shows all worker’s Id and first name
Department,Salary who gets 7000 t.k as bonus..
FROM worker where Salary=(Select
MIN(Salary) from Worker); CREATE VIEW bonus holder AS
SELECT Worker.W_id,Worker.First_Name,
bonus.bonus ammount
FROM Worker,Bonus
WHERE bonus ammount = 7000;

You might also like