0% found this document useful (0 votes)
436 views3 pages

Slip16 (Employee Investment) (1 M)

The document describes creating tables for employees and investments with a one-to-many relationship between them, where an employee can have multiple investments but each investment belongs to only one employee. It provides the table structures with primary keys and foreign key constraints and sample data is inserted. Queries are also provided to return specific data like employee details for a particular investment, total investment amount by employee, and more.

Uploaded by

akashmishra31242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
436 views3 pages

Slip16 (Employee Investment) (1 M)

The document describes creating tables for employees and investments with a one-to-many relationship between them, where an employee can have multiple investments but each investment belongs to only one employee. It provides the table structures with primary keys and foreign key constraints and sample data is inserted. Queries are also provided to return specific data like employee details for a particular investment, total investment amount by employee, and more.

Uploaded by

akashmishra31242
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Slip 16

Employee and Investment is One to Many

Consider the following entities and their relationships. Create a RDB in 3 NF with appropriate
data types and Constraints.
Employee (emp_id, emp_name, address)
Investment (inv_no, inv_name, inv_date, inv_amount)
Relation between Employee and Investment is One to Many.
Constraint: Primary key, inv_amount should be > 0.

Solution:

create table Employee16


(emp_id integer primary key,
emp_name varchar(20),
address varchar(30));

insert into employee16 values(1, 'Mr.Joshi', 'Pune');


insert into employee16 values(2,'Mr.Akash','Pune');
insert into employee16 values(3,'Mr.Kale','Mumbai');
insert into employee16 values(4,'Mr.Goyal','Gujrat');
insert into employee16 values(5,'Mr.Gole','Satara');n

create table Investment16


(inv_no integer primary key,
inv_name varchar(20),
inv_date date,
inv_amount integer,
emp_id integer,
constraint fk16 foreign key(emp_id) references employee16(emp_id));

insert into investment16 values(101,'Banglow','10-Mar-2018',2000000,1);


insert into investment16 values(102,'Land','02-Jan-2013',2500000,2);
insert into investment16 values(103,'Plot','12-Jul-2014',500000,2);
insert into investment16 values(104,'Vehicle','15-Dec-2021',500000,2);
insert into investment16 values(105,'Plot','15-Jan-2020',550000,2);
insert into investment16 values(106,'Land','18-Aug-2017',550000,3);
insert into investment16 values(107,'Ship','10-Oct-2017',1000000,4);
insert into investment16 values(108,'Mutual Fund','10-Oct-2017',10000,5);

1.Display the details of employee who has invested amount in “Mutual Fund”.

select employee16.emp_id,emp_name,address
from employee16,investment16
where inv_name='Mutual Fund'
and employee16.emp_id=investment16.emp_id;

Output:

EMP_ID EMP_NAME ADDRESS


---------- -------------------- ---------------------
5 Mr.Gole Satara
2.Add column Phone_No in Employee table.

alter table employee16


add phone_no numeric(10);

1.Display employee details who have invested more than 100000.


select employee16.emp_id,emp_name,address
from employee16,investment16
where inv_amount>100000
and employee16.emp_id=investment16.emp_id;

2.Display employee wise total investment amount.

select employee16.emp_id,emp_name,sum(inv_amount)
from employee16,investment16
where employee16.emp_id=investment16.emp_id
group by employee16.emp_id,emp_name;

3. Display the employee names who invest on date 2ndJan 2013.


select emp_name
from employee16,investment16
where inv_date='02-Jan-2013'
and employee16.emp_id=investment16.emp_id;

4. Display employee whose investment are more than 3.


select emp_id from investment16
having count(inv_no)>3
group by emp_id;
5. Find average investment of employees of Pune.

select avg(inv_amount)
from employee16,investment16
where address='Pune'
and employee16.emp_id=investment16.emp_id;

You might also like