Professional Documents
Culture Documents
GROUP ASSIGNMENT
Submitted to:
Prof. Prerna Lal
Submitted by:
Group 6
Abinash Roy (20PGDMHR03)
Lavanyaa Dhavle (20PGDMHR18)
Rohan Shrivastava (20PGDMHR37)
Shristi Shukla (20PGDMHR45)
SQL SCRIPT
PROBLEM 1
1. Construction of the database for any one of the scenarios mentioned above.
CREATE DATABASE HRISA;
SHOW DATABASES;
USE HRISA;
---- 1 ----
values(2,'ram','kapoor','alok vihar',95000,'2021-01-10','Management
Trainee','a','jamshedpur','Human Resource',831005);
---- 2 ----
insert into hr_mst(
employee_no,first_name,last_name,address,salary,doj,designation,grade,city,department,pi
n)
values(9,'ritu','ojha','ring road',30000,'2020-11-19','Analyst','d','Kochi','IT',831012);
select avg(salary)
from hr_mst;
---- 3 ----
select * from hr_mst
where salary >
(select avg(salary)
from hr_mst);
select a.employee_no,a.first_name,a.salary,a.designation,a.city,
b.days_present,b.hours_worked,
c.salary_increase
from hr_mst a,attendance b,performance_appraisal c where
a.employee_no=b.employee_no and a.employee_no=c.employee_no;
---- 4 ----
ANSWERS (SCREENSHOTS)
Displays all the data set of employees in hr_mst table entered manually with insert function.
Employee_no is taken as primary key and is not null .
Displays all the data set of employees in attendance table entered by importing from an
excel file(.csv) format.
Employee_no is taken as foreign key
---- 5 ----
Displays all the data set of employees in performance_appraisal table entered by importing
from an excel file(.csv) format.
Employee_no is taken as foreign key
● select avg(salary)
from hr_mst;
Displays the average salary of all the employees from hr_mst table
---- 6 ----
● select * from hr_mst
where salary > (select avg(salary) from hr_mst);
Displays the data of 8 employees who have their salary greater than the average salary of all
the employees
Displays the employe_ number who has got the highest salary_increase
---- 7 ----
● alter table hr_mst
add pin int;
- Added a column for employee pincodes in the hr_mst table
With this function,we have grouped the employees basis their departments they are
working and within it we have arranged them on the basis of highest to lowest salary .
---- 8 ----
SELECT CONCAT(FIRST_NAME,' ',LAST_NAME) as Employee_Name from hr_mst;
Used concat function to display full name of the employee.(joining first name and last name)
● select a.employee_no,a.first_name,a.salary,a.designation,a.city,
B.days_present,b.hours_worked,
C.salary_increase
from hr_mst a,attendance b,performance_appraisal c where
a.employee_no=b.employee_no and a.employee_no=c.employee_no;
We have used SQL aliases to join important columns from all the 3
tables(hr_mst,attendance,performance_appraisal) by using primary key(employee_no) and
---- 9 ----
foreign key(employee_no) where we have linked their employee no, first
name,salary,city,no of days present,no of hours worked with the salary increment that they
will get
● We took employee_no as primary key for the hr_mst table and set it as foreign key in
the two tables of attendance and performance_appraisal.
● Attendance table records the number of days an employee was present in a month
and the total number of hours they worked.
● Performance_appraisal table gives the salary increase which is dependent on the
total number of hours worked which is present in the attendance table and
performance evaluation by their reporting managers along with feedback which is
not uploaded in the system as it is subjective data and not quantified.
● Hence all the three tables are interdependently related to each other
---- 10 ----
PROBLEM 2
Question 1.
Output:
---- 11 ----
Question 2.
Output:
---- 12 ----
Question 3.
Output:
---- 13 ----
Question 4.
Query:
SELECT FILM.FILM_ID, FILM.TITLE, STORE.STORE_ID,
INVENTORY.INVENTORY_ID
FROM INVENTORY JOIN STORE USING (STORE_ID) JOIN FILM USING
(FILM_ID)
WHERE FILM.TITLE = 'JERK PAYCHECK' AND STORE.STORE_ID = 1 ;
SELECT INVENTORY.INVENTORY_ID
FROM INVENTORY JOIN STORE USING (STORE_ID)
JOIN FILM USING (FILM_ID)
JOIN RENTAL USING (INVENTORY_ID)
WHERE FILM.TITLE = 'JERK PAYCHECK'
AND STORE.STORE_ID = 1
AND NOT EXISTS (SELECT * FROM RENTAL
WHERE RENTAL.INVENTORY_ID = INVENTORY.INVENTORY_ID
AND RENTAL.RETURN_DATE IS NULL);
Output:
---- 14 ----
Question 4.
Query:
SELECT FIRST_NAME, LAST_NAME
FROM ACTOR
WHERE LAST_NAME = 'WINSLET'
ORDER BY FIRST_NAME;
Output:
---- 15 ----
Question 5.
Query:
SELECT CATEGORY.NAME, COUNT(FILM_CATEGORY.CATEGORY_ID)
FROM FILM_CATEGORY
JOIN CATEGORY ON FILM_CATEGORY.CATEGORY_ID =
CATEGORY.CATEGORY_ID
GROUP BY FILM_CATEGORY.CATEGORY_ID
HAVING COUNT(FILM_CATEGORY.CATEGORY_ID) BETWEEN 50 AND 60
ORDER BY COUNT(FILM_CATEGORY.CATEGORY_ID) ;
Output:
---- 16 ----
Question 6.
Query:
SELECT TITLE, REPLACEMENT_COST, RENTAL_DURATION
FROM FILM
HAVING REPLACEMENT_COST < 15 AND RENTAL_DURATION > 5
Output:
---- 17 ----