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

DBMS_Assignment

The document outlines the creation of several SQL tables related to employees, their work, locations, and management relationships. It includes SQL statements for creating tables, describing their structure, and querying specific employee information based on various conditions. The queries demonstrate how to find employees based on their birth day, city alignment with their company, and top earners at a specific company.

Uploaded by

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

DBMS_Assignment

The document outlines the creation of several SQL tables related to employees, their work, locations, and management relationships. It includes SQL statements for creating tables, describing their structure, and querying specific employee information based on various conditions. The queries demonstrate how to find employees based on their birth day, city alignment with their company, and top earners at a specific company.

Uploaded by

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

Name : Ananya Umesh Gaonkar

USN : 2SD22CS012
Branch & Division : CSE - A

Q1.Consider the schema:


EMPLOYEE (EmpID#, Empname,DOB,State,City)
WORKS (EmpID#, CompanyName,salary)
Location (CompanyName#, City#)
MANAGES (ManagerEmpID#, EmpID#)
Write the SQL Statements for the following queries.
Employee :
SQL>CREATE TABLE EMPLOYEE (
EmpID NUMBER NOT NULL PRIMARY KEY,
EmpName VARCHAR(100),
DOB DATE,
State VARCHAR(50),
City VARCHAR(50)
);
Table created.

SQL>DESC EMPLOYEECOMPANY;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER
EMPNAME CHAR(50)
DOB DATE
STATE CHAR(25)
CITY CHAR(25)

Page 1 of 6
SQL>SELECT * FROM EMPLOYEECOMPANY;
EMPID EMPNAME DOB STATE CITY
---------- ------------------------------------------- ------------ --------------------- -------------------------
9 Sumukh 24-JUL-98 Karnataka Mysore
10 Ganesh 13-JAN-95 Karnataka Ankola
1 Ananya 21-MAR-94 Karnataka Bengaluru
2 Aditi 22-JUN-92 Karnataka Mysore
3 Amay 07-APR-94 Karnataka Dharwad
4 Akshata 04-NOV-90 Karnataka Ankola
5 Anusha 19-MAR-24 Karnataka Bengaluru
6 Gagan 03-APR-95 Karnataka Mysore
8 Snehal 12-JUN-92 Karnataka Karwar

WorksFor :
SQL>CREATE TABLE WORKS (
EmpID NUMBER NOT NULL PRIMARY KEY,
CompanyName VARCHAR(100),
Salary DECIMAL(10, 2),
FOREIGN KEY (EmpID) REFERENCES EMPLOYEE
);

SQL>DESC WORKSFOR;
Name Null? Type
---------------------------------- -------- ----------------------------
EMPID NOT NULL NUMBER
COMPANYNAME CHAR(25)
SALARY NUMBER

SQL>SELECT * FROM WORKSFOR;


EMPID COMPANYNAME SALARY
---------- ------------------------- ----------
1 Innovate Ltd 85000

Page 2 of 6
2 Innovate Ltd 75000
3 FutureSolutions 90000
4 Reliance 80000
5 Innovate Ltd 95000
6 Reliance 85000
7 FutureSolutions 75000
8 Reliance 90000
9 Reliance 85000
10 Reliance 76000

Location :
SQL>CREATE TABLE LOCATION (
CompanyName VARCHAR(100),
City VARCHAR(50),
PRIMARY KEY (CompanyName, City),
FOREIGN KEY (CompanyName) REFERENCES WORKSFOR
);
TABLE CREATED.

SQL> DESC LOCATION;


Name Null? Type
----------------------------------------- -------- ----------------------------
COMPANYNAME NOT NULL CHAR(25)
CITY NOT NULL CHAR(25)

SQL>SELECT * FROM LOCATION;


COMPANYNAME CITY
------------------------- -------------------------
FutureSolutions Ankola
FutureSolutions Bengaluru
Innovate Ltd Bengaluru
Innovate Ltd Dharwad
Reliance Bengaluru
Reliance Mysore

Page 3 of 6
Manages :
SQL>CREATE TABLE MANAGES (
ManagerEmpID NUMBER NOT NULL,
EmpID NUMBER NOT NULL,
PRIMARY KEY (ManagerEmpID, EmpID),
FOREIGN KEY (EmpID) REFERENCES EMPLOYEE
);
TABLE CREATED.

SQL>DESC MANAGES;
Name Null? Type
--------------------------------- -------- ----------------------------
MANAGEREMPID NOT NULL NUMBER
EMPID NOT NULL NUMBER

SQL>SELECT * FROM MANAGES;


MANAGEREMPID EMPID
------------ ----------
1 3
1 5
4 2
4 6
4 9
7 3
7 8
7 10

Page 4 of 6
a)Find the names of all the employees who have born on Monday and live in the same city as
company for which they work.
SELECT EmpName
FROM EmployeeCompany
WHERE Trim(to_char(dob,'DAY'))='MONDAY'
INTERSECT
SELECT e.EmpName
FROM EmployeeCompany e
JOIN worksfor w on w.EmpID = e.EmpID
JOIN location l on l.companyname=w.companyname
WHERE e.city=l.city;

EMPNAME
--------------------------
Ananya
Gagan

b)Find the names of all the employees eho live in same city as their manager
SELECT e1.EmpName
FROM EmployeeCompany e1
JOIN Manages m on m.Empid = e1.EmpID
JOIN EmployeeCompany e2 on e2. EmpID= m.managerEmpID
WHERE e2.city=e1.city;

EMPNAME
--------------------
Anusha
Snehal

Page 5 of 6
c)Find the details of all employees who are the top three salary taker in Reliance
SELECT *
FROM (
SELECT ec.*, wf.salary
FROM employeeCompany ec
JOIN worksFor wf ON ec.EmpID = wf.empid
WHERE wf.companyName = 'Reliance'
ORDER BY wf.salary DESC
)
WHERE ROWNUM <= 3;

EMPID EMPNAME DOB STATE CITY SALARY


---------- ------------------------------------- --------- ------------------------ ------------------------- ----------
8 Snehal 12-JUN-92 Karnataka Karwar 90000
9 Sumukh 24-JUL-98 Karnataka Mysore 85000
6 Gagan 03-APR-95 Karnataka Mysore 85000

Page 6 of 6

You might also like