Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
916 views

SQL Project

The document describes a relational database with Employee and Manager tables and provides SQL queries to implement it and answer questions. The database stores employee ID, name, salary, address, hire date and manager ID. The SQL queries find: (1) the difference between maximum and minimum salaries; (2) employee names hired less than 5 years ago; (3) employee names earning more than their managers; and (4) employee names hired within the last year.

Uploaded by

Desis Pran
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
916 views

SQL Project

The document describes a relational database with Employee and Manager tables and provides SQL queries to implement it and answer questions. The database stores employee ID, name, salary, address, hire date and manager ID. The SQL queries find: (1) the difference between maximum and minimum salaries; (2) employee names hired less than 5 years ago; (3) employee names earning more than their managers; and (4) employee names hired within the last year.

Uploaded by

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

Consider the following relational database:

Employee (e_id,e_name,salary,address,hiredate)
Manager (e_id,manager_id)
Write SQL query for the following
Implement the above database in SQL

Find the difference between maximum and minimum salaries of employees

Find names of employees who are less than 5 years in company

Find names of employees who got higher than that of their manager

Find names of employees who joined within last one year

Question (a): Implement the above database in SQL


Answer:
SQL> create table employee(e_id number(3),e_name varchar(20),salary number(5), address
varchar(20),hiredate date);

Table created.

SQL> insert into employee values(1,'Debasis',50000,'Nandakumar','1-MAR-17');

1 row created.

SQL> insert into employee values(2,'Sunny',25000,'Maguri','1-MAR-18');

1 row created.

SQL> insert into employee values(3,'Priya',45000,'Mahishadal','1-MAR-19');

1 row created.

SQL> insert into employee values(4,'Riya',50000,'Mahishadal','1-MAR-11');

1 row created.

SQL> select*from employee;

E_ID E_NAME SALARY ADDRESS HIREDATE


---------- -------------------- ---------- -------------------- ---------
1 Debasis 50000 Nandakumar 01-MAR-17
2 Sunny 25000 Maguri 01-MAR-18
3 Priya 45000 Mahishadal 01-MAR-19
4 Riya 50000 Mahishadal 01-MAR-11

SQL> create table manager(e_id number(3),manager_id number(3));

Table created.
SQL> insert into manager values(1,1);

1 row created.

SQL> insert into manager values(2,1);

1 row created.

SQL> insert into manager values(3,3);

1 row created.

SQL> insert into manager values(4,3);

1 row created.

SQL> select*from manager;

E_ID MANAGER_ID
---------- ----------
1 1
2 1
3 3
4 3

Question (b): Find the difference between maximum and minimum salaries of
employees
Answer:
SQL> select max(salary)-min(salary) from employee;

MAX(SALARY)-MIN(SALARY)
-----------------------
25000

Question (c): Find names of employees who are less than 5 years in company
Answer:
SQL> select e_name from employee where hiredate<=(select add_months(sysdate,-60)from dual);

E_NAME
--------------------
Riya

Question (d): Find names of employees who got higher salary than that of their
managers
Answer:
SQL> select e1.e_name from employee e1,employee e2,manager m where e1.e_id=m.e_id and
e2.e_id=m.manager_id and e1.salary>e2.salary;
E_NAME
--------------------
Riya

Question (e): Find names of employees who joined within last one year
Answer:
SQL> select e_name from employee where hiredate>=(select add_months(sysdate,-12)from dual);

E_NAME
--------------------
Priya
Teacher Signature:

You might also like