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

Lab Assignment Consider The Following Tables: Sample Table - Worker

This document contains a lab assignment on writing SQL queries to analyze sample tables containing employee data. 18 questions are provided that require writing queries to retrieve employee names, departments, salaries, and other details by joining the Worker, Bonus, and Title tables based on different conditions. The questions cover basic SQL operations like selection, aggregation, filtering, ordering, joining and grouping.

Uploaded by

keziya george
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Lab Assignment Consider The Following Tables: Sample Table - Worker

This document contains a lab assignment on writing SQL queries to analyze sample tables containing employee data. 18 questions are provided that require writing queries to retrieve employee names, departments, salaries, and other details by joining the Worker, Bonus, and Title tables based on different conditions. The questions cover basic SQL operations like selection, aggregation, filtering, ordering, joining and grouping.

Uploaded by

keziya george
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Assignment

Consider the following tables:

Sample Table – Worker


WORKER_ID FIRST_NAME LAST_NAME SALARY JOINING_DATE DEPARTMENT
001 Monika Arora 100000 2014-02-20 09:00:00 HR
002 Niharika Verma 80000 2014-06-11 09:00:00 Admin
003 Vishal Singhal 300000 2014-02-20 09:00:00 HR
004 Amitabh Singh 500000 2014-02-20 09:00:00 Admin
005 Vivek Bhati 500000 2014-06-11 09:00:00 Admin
006 Vipul Diwan 200000 2014-06-11 09:00:00 Account
007 Satish Kumar 75000 2014-01-20 09:00:00 Account
008 Geetika Chauhan 90000 2014-04-11 09:00:00 Admin
Sample Table – Bonus
WORKER_REF_ID BONUS_DATE BONUS_AMOUNT
1 2016-02-20 00:00:00 5000
2 2016-06-11 00:00:00 3000
3 2016-02-20 00:00:00 4000
1 2016-02-20 00:00:00 4500
2 2016-06-11 00:00:00 3500

Sample Table – Title


WORKER_REF_ID WORKER_TITLE AFFECTED_FROM
1 Manager 2016-02-20 00:00:00
2 Executive 2016-06-11 00:00:00
8 Executive 2016-06-11 00:00:00
5 Manager 2016-06-11 00:00:00
4 Asst. Manager 2016-06-11 00:00:00
7 Executive 2016-06-11 00:00:00
6 Lead 2016-06-11 00:00:00
3 Lead 2016-06-11 00:00:00
Q-1. Write an SQL query to retrieve “FIRST_NAME” from Worker table
using the alias name as <WORKER_NAME>.

Select FIRST_NAME AS WORKER_NAME from Worker;


Q-2. Write an SQL query to retrieve “FIRST_NAME” from Worker table
in upper case.

Select upper(FIRST_NAME) from Worker;

Q-3. Write an SQL query to retrieve unique values of DEPARTMENT


from Worker table.

Select distinct DEPARTMENT from Worker;

Q-4. Write an SQL query to print the first three characters


of FIRST_NAME from Worker table.

Select substring(FIRST_NAME,1,3) from Worker;

Q-5. Write an SQL query to print the FIRST_NAME from Worker table
after removing white spaces from the right side.

Select RTRIM(FIRST_NAME) from Worker;

Q-6. Write an SQL query to print the first three characters


of FIRST_NAME from Worker table.

Select substring(FIRST_NAME,1,3) from Worker;

Q-8. Write an SQL query that retrieve the unique values of


DEPARTMENT from Worker table and prints its length.

Select distinct length(DEPARTMENT) from Worker;

Ans.
Q-9. Write an SQL query to print the FIRST_NAME from Worker table
after replacing ‘a’ with ‘A’.

Select REPLACE(FIRST_NAME,'a','A') from Worker;

Q-10. Write an SQL query to print the FIRST_NAME and LAST_NAME


from Worker table into a single column COMPLETE_NAME. A space
char should separate them.

Select CONCAT(FIRST_NAME, ' ', LAST_NAME) AS 'COMPLETE_NAME'


from Worker;

Q-11. Write an SQL query to print all Worker details from the Worker
table order by FIRST_NAME Ascending.
Select * from Worker order by FIRST_NAME asc;

Q-12. Write an SQL query to print details for Workers with the first
name as “Vipul” and “Satish” from Worker table.

Select * from Worker where FIRST_NAME in ('Vipul','Satish');

Q-13. Write an SQL query to print details of workers excluding first


names, “Vipul” and “Satish” from Worker table.

Select * from Worker where FIRST_NAME not in ('Vipul','Satish');

Q-14. Write an SQL query to print details of Workers with


DEPARTMENT name as “Admin”.

Select * from Worker where DEPARTMENT like 'Admin%';

Q-15. Write an SQL query to print details of the Workers who have
joined in Feb’2014.

Select * from Worker where year(JOINING_DATE) = 2014 and


month(JOINING_DATE) = 2;

Q-16. Write an SQL query to retrieve the count of employees working in


the department ‘Admin’.

SELECT COUNT(*) FROM worker WHERE DEPARTMENT = 'Admin';

Q-17. Write an SQL query to retrieve worker names with salaries >=
50000 and <= 100000.

SELECT CONCAT(FIRST_NAME, ' ', LAST_NAME) As Worker_Name,


Salary

FROM worker

WHERE WORKER_ID IN

(SELECT WORKER_ID FROM worker

WHERE Salary BETWEEN 50000 AND 100000);

Q-18. Write an SQL query to retrieve the no. of workers for each
department in the descending order.

SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers


FROM worker

GROUP BY DEPARTMENT

ORDER BY No_Of_Workers DESC;

You might also like