Page 1 of 70
Shri Shankaracharya Mahavidyalaya,
Junwani, Bhilai - (C.G.)
Department of Computer Science
Practical Assignment of
‘PGDCA'
On
“Relational Database Management System”
Guided By - Prepared By -
Mrs. Poonam Yadav Mr. Saket Singh Parmar
Asst. Professor PGDCA – 2nd Sem.
Dept. of Computer Science SSMV
Page 2 of 70
Sno. Aim Page no. Date of Date of Submission Signature
Practical
01 A)Create tables
B)Insert rows in the table
02 C) list the names of the
teachers teaching
computer subject:
D) List all the names of
and cities of all staff
working in your college:
E) List the name of the
cities of all staffs
working in your colleges
who earn
03 F) find the staffs whose
names starts with ‘m’ or
‘r’ ends with ‘a’ and / or
7 characters long:
G) find the staffs whose
date of joining is 2005:
H) modify the data base
so that staffs n1 now
works in c2 college:
04 I) List the name of
subject which t1 teaches
in this session or all
session
05 J) find the class that t1
do not teaches at present
session:
06 K) list the maximum,
minimum, average salary
of each colleges:
07 K(F) list the names of the
employees in ascending
order according to salary
becomes greater who
work in your college or
all college:
08 A)Create tables
B)Insert rows in the table
INDEX
Page 3 of 70
S no. Aim Page no. Date of Date of Signature
Practical submission
09) C) Get full detail of all
students who took
admission this year class
wise.
D) Get full detail of
students who took
admission in bhilai colleges
E) Calculate the total
amount of fees collected in
this session.
10) F) list the student who
have not pay full fee.
11) A) create tables
B) insert rows in the table
12) C) list the students who
were present in a paper of
a subject.
D) list all the roll numbers
who have passed in first
division
E) list all the students in
BCA II who have scored
higher than the average in
your college.
F) list the highest score,
average and minimum
score in BCA II in your
college.
Page 4 of 70
Assignment -1
A)Ques:- create following tables
Ques A) ::--- Create the tables with the given specifications and
constraints.
1)Create Table Colleges(cname , city , address, phone, Afdate)
SQL> create table colleges(cname varchar2(10) primary key, city char(15), address
varchar(15) not null, phone number(10),afdate date);
2) Create Table staffs( sid , sname , saddress , contacts )
SQL> create table staffs (sid varchar2(5) primary key, sname char(15), saddress
varchar2(15), contacts number(10));
3) Create Table Subjects (papered , subjects, paperno, papername)
SQL> create table subjects(paperid varchar2(5) primary key, subjects char(15) not null,
paperno varchar2(5), papername char(15) unique);
4) Create Table Teachings (sid, class, papered, fsession, tsession)
SQL> create table teachings(sid varchar2(5) references staffs(sid), class varchar(10),
paperid varchar2(5) references subjects(paperid), fsession date, tsession date);
5 ) Create Table Staffjoins.
SQL> create table staffjoins( sid varchar2(5) references staffs(sid), cname varchar(10)
references colleges(cname), dept varchar2(10) , doj date not null, post varchar2(10), salary
number(5));
Page 5 of 70
B)-Insert rows in the table
Insert into colleges:--
SQL> insert into colleges values('c1','bhilai','sec-6',07882225487,'12jan1985');
SQL> insert into colleges values('c2','raipur','ashok nagar',07712225487,'1jan1980');
SQL> insert into colleges values('c2','raipur','ram nagar',077432345487,'1feb1980');
SQL> insert into colleges values('c2','raipur','ram nagar',0732345487,'1feb1980');
SQL>insert into colleges values('c3','rajnandgav','risali',077222,'3mar1980');
SQL> insert into colleges values('c4','durg','ashish nagar',07725457,'2apr1991');
SQL> insert into colleges values('c5','bhilai','sector-2',25357,'22jan1996');
SQL> insert into colleges values('c6','durg','santrabadi',574678,'20jan1984');
SQL> insert into colleges values('c7','bhilai','sec-10',07882278357,'15feb1988');
SQL> insert into colleges values('c8','bhilai','hudco',07882278456,'1july1980');
SQL> insert into colleges values('c9','bhilai','sec-11',07882278456,'1mar1979');
SQL> insert into colleges values('c10','bhilai','nehru nagar',07882278456,'10aug1980');
SQL> select * from colleges;
CNAME CITY ADDRESS PHONE AFDATE
------- --------------- ------------------- ----------------- ------------------
c1 bhilai sec-6 708823509 12-JAN-85
c2 raipur ram nagar 732345487 01-FEB-80
c3 rajnandgav risali 77222 03-MAR-80
c4 durg ashish nagar 7725457 02-APR-91
c5 bhilai sector-2 25357 22-JAN-96
c6 durg santrabadi 574678 20-JAN-84
c7 bhilai sec-10 708826509 15-FEB-88
c8 bhilai hudco 708829509 01-JUL-80
c9 bhilai sec-11 708822509 01-MAR-79
Page 6 of 70
c10 bhilai nehru nagar 708821509 10-AUG-80
Insert into staffs:---
SQL>insert into staffs values('c101','rameshwara','sec-6',9857842154);
SQL> insert into staffs values('c102','rajesh','sec-2',9300875784);
SQL> insert into staffs values('c103','mayank','sec-9',9300875684);
SQL> insert into staffs values('c104','tarak','nehru nagar',9755275684);
SQL> insert into staffs values('c105','Umesh','ashok nagar',9755458744);
SQL> insert into staffs values('c106','Ramvilas','Kotma',9857442154);
SQL> insert into staffs values('c107','Arjun','sec-7',9827845987);
SQL> insert into staffs values('c108','Abhishek','Korba',9727845987);
SQL> insert into staffs values('c109','Aayush','sec-11',9755458747);
SQL> insert into staffs values('c110','Manoj','Chandigarh',9855458747);
SQL> select * from staffs;
SID SNAME SADDRESS CONTACTS
----- --------------- ------------------- -----------------------
c101 rameshwara sec-6 9857842154
c102 rajesha sec-2 9300875784
c103 mayanksec-9 9300875684
c104Tarak Nehru nagar 9755275684
c105Umesh Ashok nagar 9755458744
c106RamvilashKotma9857442154
c107 Arjunsec-7 9827845987
c108 Abhishek Korba9727845987
c109Aayushsec-11 9755458747
Page 7 of 70
c110ManojChandigarh9855458747
Insert values for staff joins:---
SQL> insert into staffjoins values('c101','c3','computer','1mar2008','teacher',10000);
SQL> insert into staffjoins values('c102','c1','maths','1april2008','principal',17000);
SQL> insert into staffjoins values('c103','c2','maths','1april2007','teacher',17000);
SQL> insert into staffjoins values('c301','c2','science','1apr2005','clerk',1000);
SQL> insert into staffjoins values('c401','c5','arts','9may2004','clerk',1000);
SQL> insert into staffjoins values('c501','c6','english','1mar2002','director',12000);
SQL> insert into staffjoins values('c601','c7','hindi','12april2007','teacher',10000);
SQL> insert into staffjoins values('c701','c8','comerc','1mar2008','teacher',10000);
SQL> insert into staffjoins values('c601','c9','maths','1aug2008','hod',11000);
SQL> insert into staffjoins values('c501','c10','hindi','1july2008','hod',11000);
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ----------------- ----------------- ---------- ---------------
c101 c3 computer 01-MAR-08 teacher 10000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 17000
c301 c2 science 01-APR-05 clerk 1000
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 10000
c701 c8 comerc 01-MAR-08 teacher 10000
c601 c9 maths 01-AUG-08 hod 11000
c501 c10 hindi 01-JUL-08 hod 11000
Page 8 of 70
Insert values for Subjects:---
SQL> insert into subjects values('sub1','Computer','101','dbms');
SQL> insert into subjects values('sub2','Arts','102','dance');
SQL> insert into subjects values('sub3','Finearts','103','sketching');
SQL> insert into subjects values('sub4','Maths','104','calculus');
SQL> insert into subjects values('sub5','Enghish','105','foundation');
SQL> insert into subjects values('sub6','Economics','106','statsistics');
SQL> insert into subjects values('sub7','Bussines ','107','accounts');
SQL> insert into subjects values('sub8','Hindi','108','mainreader');
SQL> insert into subjects values('sub9','Social ','109','history');
SQL> insert into subjects values('sub10','Science','110','physics');
SQL> select * from subjects;
PAPER SUBJECTS PAPERNO PAPERNAME
----- ----------------------- ----------------- -----------------------
Sub1computer 101 dbms
sub2 arts102 dance
sub3 finearts 103 sketching
sub4 maths 104 calculus
sub5 enghish 105 foundation
sub6 economics 106 statsistics
sub7 bussines stds 107 accounts
sub8 hindi 108 mainreader
sub9 social studies 109 history
Page 9 of 70
sub10 science 110 physics
Insert values for Teachings:---
SQL> insert into teachings values('c101','bca2','p1','1jan2007','1jan2008');
SQL> insert into teachings values('c102','bca2','p4','1mar2005','31mar2008');
SQL> insert into teachings values('c201','bca1','p5','1jan2006','1jan2008');
SQL> insert into teachings values('c301','bcom2','p6','1aug2007','1aug2008');
SQL> insert into teachings values('c401','bcom1','p7','1july2002','1july2008');
SQL> insert into teachings values('c501','bcom2','p5','1sep2003','1sep2008');
SQL> insert into teachings values('c601','bsc1','p10','1feb2001','31mar2008');
SQL> insert into teachings values('c701','bsc2','p10','1mar2007','31mar2008');
SQL> insert into teachings values('c601','bba2','p7','1july2004','1july2008');
SQL> insert into teachings values('c501','bba1','p2','1jan2003','1jan2008');
SQL> select * from teachings;
SID CLASS PAPER FSESSION TSESSION
-------- --------------- -------------- -------------------- ---------------------
c101 bca2 p1 01-JAN-07 01-JAN-08
c102 bca2 p4 01-MAR-05 31-MAR-08
c201 bca1 p5 01-JAN-06 01-JAN-08
c301 bcom2 p6 01-AUG-07 01-AUG-08
c401 bcom1 p7 01-JUL-02 01-JUL-08
c501 bcom2 p5 01-SEP-03 01-SEP-08
c601 bsc1 p10 01-FEB-01 31-MAR-08
c701 bsc2 p10 01-MAR-07 31-MAR-08
c601 bba2 p7 01-JUL-04 01-JUL-08
Page 10 of 70
c501 bba1 p2 01-JAN-03 01-JAN-08
c)- list the names of the teachers teaching computer subject:
SQL> select sname from staffs where sid=(select sid from teachings where paperid =(select
paperid from subjects where subjects='computer'));
SNAME
---------------
rameshwara
D)- List all the names os and cities of all staff worling in your college:
SQL> select sname, saddress from staffs where sid=(select sid from staffjoins where
cname='c1');
SNAME SADDRESS
--------------- ---------------
rajesha sec-2
E)- List the name of the cities of all staffs working in your colleges who earn
More than 15000:
SQL> select sname,saddress from staffs where sid =(select sid from staffjoins where cname
='c1' and salary>15000);
SNAME SADDRESS
--------------- ---------------
rajesha sec-2
Page 11 of 70
F)- find the staffs whose names starts with ‘M’ or ‘R’ ends with ‘A’ and / or 7
characters long:
SQL> select sname from staffs where sname like 'm_____%a' or sname like 'r____%a';
SNAME
---------------
rameshwara
manyata
G)- find the staffs whose date of joining is 2005:
SQL> select sname from staffs where sid=(select sid from staffjoins where extract(year
from doj)=2005);
SNAME
---------------
n1
H)-modify the data base so that staffs n1 now works in c2 college:
SQL> update staffjoins set cname='c2' where sid=(select sid from staffs where sname='n1');
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ------------ --------- ---------- ---------
c101 c3 computer 01-MAR-08 teacher 10000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 17000
c301 c2 science 01-APR-05 clerk 1000
Page 12 of 70
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 10000
c701 c8 comerc 01-MAR-08 teacher 10000
c601 c9 maths 01-AUG-08 hod 11000
c501 c10 hindi 01-JUL-08 hod 11000
I)List the name of subject which t1 teaches in this session or all session:
SQL> select subjects from subjects where paperid=(select paperid from teachings where
(extract (year from fsession)=07 or fsession is not null) and sid=(select sid from staffs where
sname='t1'));
SUBJECTS
---------------
english
(J) find the class that t1 do not teaches at present session:
SQL>select class from teachings where extract (year from fsession)<>07 and sid=(select sid from
staffs where sname='t1');
CLASS
----------
bca1
J(A) find the colleges who have most no of staffs:
SQL>select cname , count(sid) from staffjoins group by cname having count(sid)>=2 order by
count(sid);
CNAME COUNT(SID)
---------- ---------------
c2 2
Page 13 of 70
J(B) find the staffs that earn a higher salary who earn greater than average
salary of their college:
SQL> select salary from staffjoins where cname like 'c2' and salary>(select avg(salary) from
staffjoins group by cname having cname like 'c2');
SALARY
---------
1700
J(C) find the colleges whose average salary is more than average salary of c2:
SQL>select cname, avg(salary) from staffjoins group by cname having avg(salary)>(select
avg(salary) from staffjoins where cname='c2');
CNAME AVG(SALARY)
---------- -----------
c1 17000
c10 11000
c3 10000
c6 12000
c7 10000
c8 10000
c9 11000
J(D) find the colleges that has the smallest payroll:
SQL> select cname from staffjoins where salary=(select min(salary) from
staffjoins);
CNAME
--------
c2
Page 14 of 70
c5
J(E ) find the colleges where the total salary is greater than the average salary of all
colleges:
SQL> select cname, sum(salary) from staffjoins group by cname having sum(salary)>(select
avg(sum(salary)) from staffjoins group by cname);
CNAME SUM(SALARY)
---------- -----------
c1 17000
c2 18000
c6 12000
K ) list the maximum, minimum, average salary of each colleges:
SQL> select cname, max(salary) "max salary", avg(salary) "avg salary", min(salary) "min
salary" from staffjoins group by cname;
CNAME MAX SALARY AVG SALARY MIN SALARY
---------- -----------------------------------------------------------
c1 17000 17000 17000
c10 11000 11000 11000
c2 17000 9000 1000
c3 10000 10000 10000
c5 1000 1000 1000
c6 12000 12000 12000
c7 10000 10000 10000
c8 10000 10000 10000
c9 11000 11000 11000
K(A) list the name of the teachers department teaching in more than 1
depart ment:
Page 15 of 70
SQL>select sname, dept from staffs, staffjoins where [Link]=[Link] and [Link]
in(select sid from staffjoins group by sid having count(sid)>1);
SNAME DEPT
--------------- ----------
t3 english
t3 hindi
t4 hindi
t4 maths
K(B) Acquire details of staffs by name in a colleges or each college:
SQL> select [Link], sname, saddress, contacts, dept, doj, post, salary from staffs, staff
joins where [Link]=[Link] order by sname;
SID SNAME SADDRESS CONTACTS DEPT DOJ POST SALARY
----- --------------- --------------- ------------ ---------- ---------- --------- ---------- ---------
c103 manyata sec-9 993010509maths 01-APR-07 teacher 17000
c301 n1 sec-11 997550509science 01-APR-05 clerk 1000
c401 n2 sec-1 998550509 arts 09-MAY-04 clerk 1000
c102 rajesha sec-2 993010509 maths 01-APR-08 principal 17000
c101 rameshwara sec-6 998580509 computer 01-MAR-08 teacher 10000
c501 t3 sec-5 998570509 english 01-MAR-02 director 12000
c501 t3 sec-5 998570509 hindi 01-JUL-08 hod 11000
c601 t4 sec-7 998280509 hindi 12-APR-07 teacher 10000
c601 t4 sec-7 998285509 maths 01-AUG-08 hod 11000
c701 t5 sec-3 997285509 comerc 01-MAR-08 teacher 10000
Page 16 of 70
K(C) Find the names of the staff that earn more than each staff of C2
college:
SQL> select sname from staffs,staffjoins where [Link]=[Link] and salary>(select
max(salary) from staffjoins where cname like 'c2');
SNAME
---------------
rajesha
t3
t4
t3
K(D) Give all teachers a 10% rise in salary unless their salary becomes
greater than 20000:
SQL> update staffjoins set salary=5salary*0.1 where(salary5salary*0.1)< 20000 and
post='teacher';
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ---------- --------- ---------- ---------
c101 c3 computer 01-MAR-08 teacher 1000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 1700
c301 c2 science 01-APR-05 clerk 1000
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 1000
Page 17 of 70
c701 c8 comerc 01-MAR-08 teacher 1000
c601 c9 maths 01-AUG-08 hod 11000
c501 c10 hindi 01-JUL-08 hod 11000
K(E) Find the staff that do not work in same cities as the college they work.
SQL> select sname from staffs s,colleges c,staffjoins j where [Link]=[Link] and [Link]=[Link] and
[Link]<>[Link];
SNAME
---------------
rameshwara
rajesha
manyata
n1
n2
t3
t4
t5
t4
t3
K(F) list the names of the employees inascending order according to salary
becomes greater who work in your college or all college:
SQL> Select [Link], [Link], [Link] from staffs st, staffjoins sj where [Link]=[Link] order by
[Link];
SID SNAME SALARY
----- --------------- ---------
c101 rameshwara 1000
c301 n1 1000
c601 t4 1000
c401 n2 1000
c701 t5 1000
c103 manyata 1700
Page 18 of 70
c601 t4 11000
c501 t3 11000
c501 t3 12000
c102 rajesha 17000
K(F)(a) Create a view having fields sname, dept, doj and post:
SQL> create view staffdetails as select sname,cname,dept,doj,post from staffs,staffjoins where
[Link]=[Link];SQL> select * from staffdetails;
SNAME CNAME DEPT DOJ POST
------------ -------------- --------- --------------------------
rameshwara c3 computer 01-MAR-08 teacher
rajesha c1 maths 01-APR-08 principal
manyata c2 maths 01-APR-07 teacher
n1 c2 science 01-APR-05 clerk
n2 c5 arts 09-MAY-04 clerk
t3 c6 english 01-MAR-02 director
t4 c7 hindi 12-APR-07 teacher
t5 c8 comerc 01-MAR-08 teacher
t4 c9 maths 01-AUG-08 hod
t3 c10 hindi 01-JUL-08 hod
K(F)(b) Create a view consisting of cname average salary and total salary of
all staff in that colleges:
SQL> create view college_sal as select cname,round(avg(salary),2)"Average",sum(salary)"Total"
from staffjoins group by cname;
SQL> select * from college_sal;
CNAME Average Total
---------- --------- ---------
c1 17000 17000
c10 11000 11000
c2 1350 2700
c3 1000 1000
c5 1000 1000
Page 19 of 70
c6 12000 12000
c7 1000 1000
c8 1000 1000
c9 11000 11000
K(F)(c) list the staff names of a department using above views:
SQL> select dept,cname,sname from staffdetails s where [Link]=dept;
DEPT CNAME SNAME
---------- ---------- ---------------
computer c3 rameshwara
maths c1 rajesha
maths c2 manyata
science c2 n1
arts c5 n2
english c6 t3
hindi c7 t4
comerc c8 t5
maths c9 t4
hindi c10 t3
Page 20 of 70
Assignment -2
A) Ques:- create following tables
Ques A) ::--- Create the tables with the given specifications and
constraints.
Create table:- Enrollment
SQL>create table enrollment(enrollno varchar2(10 ) primary key, name
varchar(10), gender varchar2(7),dob date, address varchar2(20),phone
number(10));
Create table:- Fees structure
SQL> create table feestructure(course varchar2(10), yearsem varchar2(10), fee
number(6), constraint feestructure primary key(course, yearsem));
Create table:- college
SQL> create table college(cname varchar2(10), city varchar2(10), address
varchar2(10),phone number(10), afdate date, constraint college primary key
(cname));
Create table :-admission
SQL>create table admn(admno number(10) primary key,enrollno number(10)
references enrollment(enrollno)
course varchar2(10),
yearsem number(10),
dob date,
cname varchar2(20));
Page 21 of 70
Create table:- payment
SQL> create table payment(billno number(5) primary key, admno references
admission, amount number(8), pdate date , purpose varchar2(15));
INSERT ROWS IN ENROLLMENT
SQL> insert into enrollment values('1001','khyati','6-nov-89','bhilai',9755721881,'female');
SQL> insert into enrollment values('1002','nikhil','15-april-89','durg',9542135057,'male');
SQL> insert into enrollment values('1003','jyoti','2-feb-90','bhilai',9178927568,'Female');
SQL> insert into enrollment values('1004','anil','19-dec-88','charoda',9302972563,'male');
SQL> insert into enrollment values('1005','swati','8-dec-88','raipur',9814475345,'female');
SQL> insert into enrollment values('1006','manish','28-jul-87','bhilai',9893046469,'male');
SQL> insert into enrollment values('1007','anand','05-dec-88','Korba’,9872344369,'male');
SQL> insert into enrollment values('1008','ruma','30-jan-88','bhilai',9755760892,'female');
SQL> insert into enrollment values('1009','kiran','9-sep-89','bhilai',9893587861,'female');
SQL> insert into enrollment values('1010','usha','20-april-88', 'durg',9755764634,'female');
SQL> select * from enrollment;
ENROLLNO NAME GENDER DOB ADDRESS PHONE
---------- ---------- --------------- --------- -------------------- ---------------
1001 khyati female 06-NOV-89 bhilai 9755721881
1002 nikita female 15-APR-89 durg 954213505
1003 jyoti female 02-FEB-90bhilai 91789275
1004 anil male 19-DEC-88 charoda 9302972
1005 swati female 08-DEC-88 raipur 981447534
1006 manish male 28-JUL-87 bhilai 9893046469
1007 anand male 05-DEC-88 nehru nagar 9872344
1008 ruma female 30-JAN-88 bhilai 975576089
Page 22 of 70
1009 kiran female 09-SEP-89 bhilai 989358786
1010 usha female 20-APR-88 durg 94567777899
INSERT ROWS IN FEESTRUCTURE:
SQL>insert into feestructure values('bca2','2009-2009',20000);
SQL>insert into feestructure values('bca3','2009-2009',21000);
SQL>insert into feestructure values('bca1','2009-2009',20000);
SQL>insert into feestructure values('bcom3','2009-2009',22000);
SQL>insert into feestructure values('bcom2','2007-2008',18000);
SQL>insert into feestructure values('bcom1','2006-2007',10000);
SQL>insert into feestructure values('bsc3','2008-2009',12000);
SQL>insert into feestructure values('bba3','2004-2005',8000);
SQL>insert into feestructure values('ba3','2004-2005',8000);
SQL>insert into feestructure values('bca3','2007-2008',22000);
SQL> select * from feestructure;
COURSE YEARSEM FEE
---------- ---------- ----------
bca2 2009-2009 20000
bca3 2009-2009 21000
bca1 2009-2009 20000
bcom3 2009-2009 22000
bcom2 2007-2008 18000
bcom1 2006-2007 10000
bsc3 2008-2009 12000
bba3 2004-2005 8000
Page 23 of 70
ba3 2004-2005 8000
bca3 2007-2008 22000
INSERT ROWS IN COLLEGE:-
SQL>insert into college values('shankara','bhilai','sec-6','2224567523','19-jul-1990');
SQL>insert into college values('kalyan','durg','hudco','2673656','1-feb-1990');
SQL>insert into college values('shivam','bhilai','hudco','2673656','19-july-1989');
SQL>insert into college values('disha','bhilai','hudco','2673656','19-july-1998');
SQL>insert into college values('boysclg','durg','sec-1','2673656','21-feb-1998');
SQL>insert into college values('girlsclg','durg','sec-10','2673656','12-feb-1998');
SQL>insert into college values('Bit','camp','sec-10','2673656','12-march-1998');
SQL>insert into college values('science','raipur','sec-10','2673656','12-march-1998');
SQL>insert into college values('rungta','kohka','sec-2','2673656','12-april-1998');
SQL>insert into college values('dental','kohka','sec-2','2673656','1-aug-1988');
SQL> select * from college;
CNAME CITY ADDRESS PHONE AFDATE
---------- ---------- ---------- ---------- ---------
shankara bhilai sec-6 2224567 19-JUL-90
kalyan durg hudco 2673656 01-FEB-90
shivam bhilai hudco 2673656 19-JUL-89
disha bhilai hudco 2673656 19-JUL-98
boysclg durg sec-1 2673656 21-FEB-98
girlsclg durg sec-10 2673656 12-FEB-98
Bit camp sec-10 2673656 12-MAR-98
Page 24 of 70
science raipur sec-10 2673132 12-MAR-98
rungta kohka sec-2 26735566 12-APR-98
dental kohka sec-2 2673656 01-AUG-88
INSERT ROWS IN ADMISSION:-
SQL>insertinto admission values(1,1001,’bca2’,’2009-2009’,’20-jun-09’,’shankara’);
SQL>insertinto admission values(2,1002,’bca3’,’2009-2009’, 05-AUG-08’,’kalyan’);
SQL>insert into admission values(3,1003,’bcom2’,’2007-2008’,’ 18-SEP-07,’ shivam’);
SQL>insertinto admission values(4,1004,’bba3’,’2004-2005’, 14-JUN-05’,’ disha’);
SQL>insertinto admission values(5,1005,’ba3’,’2004-2005’,’ 20-APR-04’,’ girlsclg’);
SQL>insert into admission values(6,1006,’bcom1’,’2006-2007’,’ 15-AUG-07’,’ boysclg’);
SQL>insert into admission values(7,1007,’bcom3’,’2009-2009’,’ 13-JUL-08’,’ Bit’);
SQL>insert into admission values(8,1008,’bca1’,’2009-2009’,’ 23-FEB-09’,’ rungta’);
SQL>insert into admission values(9,1009,’bsc3’,’2008-2009’,’ 20-JAN-09’,’ science’);
SQL>insert into admission values(10,1010,’bcom1’,’2006-2007’,’ 20-FEB-07’,’ dental’);
SQL> select * from admissions;
ADMNO ENROLLNO COURSE YEARSEM DOA CNAME
------------- ------------- ------------- ------------------------ --------------------
1 1001 bca2 2009-2009 20-JUN-09 shankara
2 1002 bca3 2009-2009 05-AUG-08 kalyan
3 1003 bcom2 2007-2008 18-SEP-07 shivam
4 1004 bba3 2004-2005 14-JUN-05 disha
5 1005 ba3 2004-2005 20-APR-04 girlsclg
6 1006 bcom1 2006-2007 15-AUG-07 boysclg
Page 25 of 70
7 1007 bcom3 2009-2009 13-JUL-08 Bit
8 1008 bca1 2009-2009 23-FEB-09 rungta
9 1009 bsc3 2008-2009 20-JAN-09 science
10 1010 bcom1 2006-2007 20-FEB-07 dental
INSERT ROWS IN PAYMENT:-
SQL>insert into payment values(1,1,10000,’20-jun-08’,’admn fee’);
SQL>insert into payment values(2,2,10500,’ 17-JUN-08’,’tution fee’);
SQL>insert into payment values(3,3,20000,’ 08-JUL-08’,’ tution fee’);
SQL>insert into payment values(4,4,11000,’ 05-AUG-08’,’admn fee’);
SQL>insert into payment values(5,5,9000,’ 05-JUN-07’,’admn fee’);
SQL>insert into payment values(6,6,10000,’ 06-SEP-06’,’tution fee’);
SQL>insert into payment values(7,7,12000,’ 05-MAY-08’,’tution fee’);
SQL>insert into payment values(8,8,8000,’ 09-SEP-04’,’tution fee’);
SQL>insert into payment values(9,9,5000,’ 05-JUL-08’,’admn fee’);
SQL>insert into payment values(10,10,11000,’ 06-JUN-07’,’admn fee’);
SQL> select * from payment;
BILLNO ADMNO AMOUNT PDATE PURPOSE
------------- -------------- --------------- ------------- ---------------
1 1 10000 20-JUN-08 admn fee
2 2 10500 17-JUN-08 tution fee
3 3 20000 08-JUL-08 tution fee
4 4 11000 05-AUG-08 admn fee
5 5 9000 05-JUN-07 admn fee
6 6 10000 06-SEP-06 tution fee
Page 26 of 70
7 7 12000 05-MAY-08 tution fee
8 8 8000 09-SEP-04 tution fee
9 9 5000 05-JUL-08 admn fee
10 10 11000 06-JUN-07 admn fee
D)Get full detail of students who took admission in bhilai college
SQL> select * from enrollment where enrollno in(select enrollno from admissions where cname
in(select cname from college where city='bhilai'));
ENROLLNO NAME GENDER DOB ADDRESS PHONE
---------- ---------- ------- --------- -------------------- ---------
1001 khyati female 06-NOV-89 bhilai 975667009
1003 jyoti female 02-FEB-90 bhilai 917892750
1004 anil male 19-DEC-88 charoda 930297872
E) Calculate the total amount of fees collected in this session
i) by your college
SQL select sum (p. amount) "Total fee" from payment p, admissions a where [Link]=[Link]
and [Link] like '2008-2009' and [Link] like 'shankara';
Total fee
----------
10000
ii) by all college
SQL>select sum([Link]) "Total fee" from payment p,admissions a where [Link]=[Link]
and [Link] like '2008-2009';
Page 27 of 70
Total fee
---------
5000
F)List the student who have not pay full fee.
i) in your college
SQL>select [Link] from enrollment e, admissions a, feestructure f, payment p where
[Link]=[Link] [Link]=[Link] and [Link]=[Link] and [Link]=[Link]
and [Link]> [Link] and [Link]='shankara';
NAME
----------
Khyati
ii) in other college
SQL>select [Link] from enrollment e, admissions a, feestructure f, payment p where
enrollno=[Link] and [Link]=[Link] [Link]=[Link] and [Link]=[Link] and
[Link]> [Link];
NAME
----------
khyati
nikita
anand
ruma
kiran
Page 28 of 70
F(c)List the names of the student in the session who are not in the college in
the same city as they live in.
SQL>select [Link] from enrollment e, admissions a, college c where [Link]=[Link] and
[Link]=[Link] and [Link]<> [Link] and [Link]='2008-2009’;
NAME
----------
kiran
F(d)List the names of the student in your college and city and also live in your
city.
SQL>select [Link] from enrollment e, admissions a, college c where [Link]=[Link] and
[Link]=[Link] and [Link]= [Link];
NAME
----------
khyati
nikita
jyoti
Page 29 of 70
Assignment -3
A) Ques:- Create following tables:
Ques A) ::--- Create the tables with the given specifications and
constraints.
Create table:-Subject
SQL> create table subject(paperid varchar2(10) primary key, subjects
varchar2(20),paper varchar2(10), papername varchar2(15));
Create table:-Test
SQL>create table test (paperid references subject, doe date, time
varchar2(10),max varchar2(5), min varchar2(5));
Create table:-Score
SQL>create table score(rollno varchar2(10) primary key, paperid references
subject, marks number(5), attendence char(1) check(attendence='a' or
attendence='p' or attendence='A' or attendence='P'));
Create table:-Students
SQL> create table students(admno varchar2(5) primary key, rollno references
score, class varchar2(10), yearsem varchar2(10));
Page 30 of 70
INSERT ROWS INTO SUBJECT:
SQL> insert into subject values('p1','computers','101','dbms');
SQL> insert into subject values('p2','arts','102',' dance ');
SQL>insert into subject values('p3',' finearts ','103','sketching');
SQL> insert into subject values('p4','maths','104','calculus');
SQL> insert into subject values('p5','english','105','foundation');
SQL> insert into subject values('p6','economics','106','statitics');
SQL> insert into subject values('p7','businessstds','107','accounts');
SQL> insert into subject values('p8','hindi','108','mainreader');
SQL> insert into subject values('p9','social science','109','history');
SQL> insert into subject values('p10','maths','110','physics');
SQL> select * from subject;
PAPER SUBJECTS PAPER PAPERNAME
----- --------------- ----------- -------------------
p1 computer 101 dbms
p2 arts 102 dance
p3 finearts 103 sketching
p4 maths 104 calculus
p5 enghish 105 foundation
p6 economics 106 statsistics
p7 bussines stds 107 accounts
p8 hindi 108 mainreader
p9 social studies 109 history
Page 31 of 70
p10 science 110 physics
INSERT ROWS INTO TEST:
SQL>insert into test values(‘1‘,’01-MAR-09 11 am ‘,’100‘,’40’);
SQL>insert into test values('sub2’,’05-MAR-09’,’11 am’,’50’,’20');
SQL>insert into test values('sub3’,’07-MAR-09’,’ 11 am’,’50’,’20');
SQL>insert into test values('sub4’,’10-MAR-09’,’ 11 am’,’50’,’20');
SQL>insert into test values('sub5’,’12-MAR-09’,’ 11 am ‘,’100 ‘,’40');
SQL>insert into test values('sub6’,’14-MAR-09’,’ 11 am’,’100 ‘,’40');
SQL>insert into test values('sub7’,’17-MAR-09’,’ 11 am’,’100’,’40');
SQL>insert into test values('sub8’,’20-MAR-09’,’ 11 am’,’50’,’20');
SQL>insert into test values('sub9’,’22-MAR-09’,’ 11 am’,’50’,’20');
SQL>insert into test values('sub10’,’24-MAR-09 ‘,’11 am’,’100’,’40');
SQL> select * from test;
PAPER DOT TIME MAX MIN
----- --------- ---------- --------- -------------- ----------
1 01-MAR-09 11 am 100 40
2 05-MAR-09 11 am 50 20
3 07-MAR-09 11 am 50 20
4 10-MAR-09 11 am 50 20
5 12-MAR-09 11 am 100 40
6 14-MAR-09 11 am 100 40
7 17-MAR-09 11 am 100 40
8 20-MAR-09 11 am 50 20
9 22-MAR-09 11 am 50 20
Page 32 of 70
10 24-MAR-09 11 am 100 40
INSERT ROWS INTO SCORE:
SQL>insert into score values('r001‘,’1’,’81’,’present');
SQL> insert into score values('r002’,’2 ‘,’70‘,’absent');
SQL>insert into score values('r003’,’3’,’50’,’ present');
SQL>insert into score values('r004’,’4’,’62 ‘,’present');
SQL>insert into score values('r005’,’5’,’30 ‘,’present');
SQL>insert into score values('r006’,’6’,’ 40‘,’absent');
SQL>insert into score values('r007’,’7’,’77’,’present');
SQL>insert into score values('r008‘,’8’,’20’,’ present');
SQL>insert into score values('r009‘,’9‘,’80’,’ present');
SQL>insert into score values('r010’,’10‘,’88‘,’present');
SQL> select * from score;
ROLLNO PAPER MARKS ATTENDANCE
--------- --------- ------------ --------------------
r001 1 81 present
r002 2 absent
r003 3 50 present
r004 4 62 present
r005 5 30 present
r006 6 absent
r007 7 77 present
r008 8 20 present
r009 9 80 present
Page 33 of 70
r010 10 88present
INSERT ROWS INTO STUDENTS:
SQL>insert into students values('a001','r001','bca2','2008-2009');
SQL>insert into students values('a002','r002','bca2','2008-2009');
SQL>insert into students values('a003','r003','bca2','2008-2009');
SQL>insert into students values('a004','r004','bca2','2008-2009');
SQL>insert into students values('a005','r005','bca2','2008-2009');
SQL>insert into students values('a006','r006','bca2','2008-2009');
SQL>insert into students values('a007','r007','bca2','2008-2009');
SQL>insert into students values('a008','r008','bca2','2008-2009');
SQL>insert into students values('a009','r009','bca2','2008-2009');
SQL>insert into students values('a110','r010','bca2','2008-2009');
SQL> select * from students;
ADMNO ROLLNOCLASS YEARSEM
------------- -------------- ----------- ---------------
a001 r001 BCA-I 2ndsem
a002 r002 BCA-II 1stsem
a003 r003 BCA-III 2ndsem
a004 r004 BCA-II 2ndsem
a005 r005 BCA-II 1stsem
a006 r006 BCA-I 1stsem
a007 r007 BCA-III 1stsem
a008 r008 BCA-II 2ndsem
a009 r009 BCA-III 1stsem
Page 34 of 70
a010 r010 BCA-II 1stsem
C ) List the students who were present in a paper of a subject.
SQL> select [Link] from students, score where ([Link]=[Link] and
attendance='present');
ROLLNO
-----
r001
r003
r004
r005
r007
r008
r009
r010
D) List all the roll numbers who have passed in first division.
SQL> select rollno from score where marks>=60;
ROLLNO
-----
r001
r004
r007
r009
r010
Page 35 of 70
E) List all the students in BCA II who have scored higher then the average in
your college.
SQL>select [Link],marks from students, score where
[Link]=[Link] and marks>(select avg(marks) from score,students where
class='BCA-II' and [Link]=[Link]);
ROLLNO MARKS
----- ---------
r001 81
r004 62
r007 77
r009 80
r010 88
F) List the highest score, average and minimum score in BCA II in your
college.
SQL>select max(marks), avg(marks), min(marks) from score, students
where [Link]=[Link] and class='BCA-II' group by class;
MAX(MARKS) AVG(MARKS) MIN(MARKS)
---------- ---------- ----------
88 50 20
Page 36 of 70
Assignment -4
Ques A) ::--- create following tables
Ques A) ::--- Create the tables with the given specifications and
constraints.
Create Table Colleges(cname , city , address, phone, Afdate)
SQL> create table colleges(cname varchar2(10) primary key, city char(15), address
varchar(15) not null, phone number(10),afdate date);
Create Table staffs ( sid , sname , saddress , contacts )
SQL> create table staffs (sid varchar2(5) primary key, sname char(15), saddress
varchar2(15), contacts number(10));
Create Table Subjects (papered , subjects, paperno, papername)
SQL> create table subjects(paperid varchar2(5) primary key, subjects char(15) not null,
paperno varchar2(5), papername char(15) unique);
Create Table Teachings (sid, class, papered, fsession, tsession)
SQL> create table teachings(sid varchar2(5) references staffs(sid), class varchar(10),
paperid varchar2(5) references subjects(paperid), fsession date, tsession date);
Create Table Staffjoins.
Page 37 of 70
SQL> create table staffjoins( sid varchar2(5) references staffs(sid), cname varchar(10)
references colleges(cname), dept varchar2(10) , doj date not null, post varchar2(10), salary
number(5));
B)-Insert rows in the table
Insert into colleges:--
SQL> insert into colleges values('c1','bhilai','sec-6',07882225487,'12jan1985');
SQL> insert into colleges values('c2','raipur','ashok nagar',07712225487,'1jan1980');
SQL> insert into colleges values('c2','raipur','ram nagar',077432345487,'1feb1980');
SQL> insert into colleges values('c2','raipur','ram nagar',0732345487,'1feb1980');
SQL>insert into colleges values('c3','rajnandgav','risali',077222,'3mar1980');
SQL> insert into colleges values('c4','durg','ashish nagar',07725457,'2apr1991');
SQL> insert into colleges values('c5','bhilai','sector-2',25357,'22jan1996');
SQL> insert into colleges values('c6','durg','santrabadi',574678,'20jan1984');
SQL> insert into colleges values('c7','bhilai','sec-10',07882278357,'15feb1988');
SQL> insert into colleges values('c8','bhilai','hudco',07882278456,'1july1980');
SQL> insert into colleges values('c9','bhilai','sec-11',07882278456,'1mar1979');
SQL> insert into colleges values('c10','bhilai','nehru nagar',07882278456,'10aug1980');
SQL> select * from colleges;
CNAME CITY ADDRESS PHONE AFDATE
------- --------------- ------------------- ----------------- ------------------
c1 bhilai sec-6 708823509 12-JAN-85
c2 raipur ram nagar 732345487 01-FEB-80
c3 rajnandgav risali 77222 03-MAR-80
c4 durg ashish nagar 7725457 02-APR-91
c5 bhilai sector-2 25357 22-JAN-96
c6 durg santrabadi 574678 20-JAN-84
c7 bhilai sec-10 708826509 15-FEB-88
Page 38 of 70
c8 bhilai hudco 708829509 01-JUL-80
c9 bhilai sec-11 708822509 01-MAR-79
c10 bhilai nehru nagar 708821509 10-AUG-80
Insert into staffs:---
SQL>insert into staffs values('c101','rameshwara','sec-6',9857842154);
SQL> insert into staffs values('c102','rajesha','sec-2',9300875784);
SQL> insert into staffs values('c103','manyata','sec-9',9300875684);
SQL> insert into staffs values('c201','t1','nehru nagar',9755275684);
SQL> insert into staffs values('c202','t2','ashok nagar',9755458744);
SQL> insert into staffs values('c501','t3','sec-5',9857442154);
SQL> insert into staffs values('c601','t4','sec-7',9827845987);
SQL> insert into staffs values('c701','t5','sec-3',9727845987);
SQL> insert into staffs values('c301','n1','sec-11',9755458747);
SQL> insert into staffs values('c401','n2','sec-1',9855458747);
SQL> select * from staffs;
SID SNAME SADDRESS CONTACTS
----- --------------- ------------------- -----------------------
c101 rameshwara sec-6 958580563
c102 rajesha sec-2 9530105879
c103 manyata sec-9 953010589
c201 t1 nehru nagar 957550505
c202 t2 ashok nagar 957550506
c501 t3 sec-5 95857567
c601 t4 sec-7 958280567
c701 t5 sec-3 95723432
c301 n1 sec-11 957550511
Page 39 of 70
c401 n2 sec-1 958550122
Insert values for staffjoins:---
SQL> insert into staffjoins values('c101','c3','computer','1mar2008','teacher',10000);
SQL> insert into staffjoins values('c102','c1','maths','1april2008','principal',17000);
SQL> insert into staffjoins values('c103','c2','maths','1april2007','teacher',17000);
SQL> insert into staffjoins values('c301','c2','science','1apr2005','clerk',1000);
SQL> insert into staffjoins values('c401','c5','arts','9may2004','clerk',1000);
SQL> insert into staffjoins values('c501','c6','english','1mar2002','director',12000);
SQL> insert into staffjoins values('c601','c7','hindi','12april2007','teacher',10000);
SQL> insert into staffjoins values('c701','c8','comerc','1mar2008','teacher',10000);
SQL> insert into staffjoins values('c601','c9','maths','1aug2008','hod',11000);
SQL> insert into staffjoins values('c501','c10','hindi','1july2008','hod',11000);
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ----------------- ----------------- ---------- ---------------
c101 c3 computer 01-MAR-08 teacher 10000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 17000
c301 c2 science 01-APR-05 clerk 1000
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 10000
c701 c8 comerc 01-MAR-08 teacher 10000
c601 c9 maths 01-AUG-08 hod 11000
Page 40 of 70
c501 c10 hindi 01-JUL-08 hod 11000
Insert values for Subjects:---
SQL> insert into subjects values('p1','computer','101','dbms');
SQL> insert into subjects values('p2','arts','102','dance');
SQL> insert into subjects values('p3','finearts','103','sketching');
SQL> insert into subjects values('p4','maths','104','calculus');
SQL> insert into subjects values('p5','enghish','105','foundation');
SQL> insert into subjects values('p6','economics','106','statsistics');
SQL> insert into subjects values('p7','bussines stds','107','accounts');
SQL> insert into subjects values('p8','hindi','108','mainreader');
SQL> insert into subjects values('p9','social studies','109','history');
SQL> insert into subjects values('p10','science','110','physics');
SQL> select * from subjects;
PAPER SUBJECTS PAPERNO PAPERNAME
----- ----------------------- ----------------- -----------------------
p1 computer 101 dbms
p2 arts102 dance
p3 finearts 103 sketching
p4 maths 104 calculus
p5 enghish 105 foundation
p6 economics 106 statsistics
p7 bussines stds 107 accounts
p8 hindi 108 mainreader
p9 social studies 109 history
Page 41 of 70
p10 science 110 physics
Insert values for Teachings:---
SQL> insert into teachings values('c101','bca2','p1','1jan2007','1jan2008');
SQL> insert into teachings values('c102','bca2','p4','1mar2005','31mar2008');
SQL> insert into teachings values('c201','bca1','p5','1jan2006','1jan2008');
SQL> insert into teachings values('c301','bcom2','p6','1aug2007','1aug2008');
SQL> insert into teachings values('c401','bcom1','p7','1july2002','1july2008');
SQL> insert into teachings values('c501','bcom2','p5','1sep2003','1sep2008');
SQL> insert into teachings values('c601','bsc1','p10','1feb2001','31mar2008');
SQL> insert into teachings values('c701','bsc2','p10','1mar2007','31mar2008');
SQL> insert into teachings values('c601','bba2','p7','1july2004','1july2008');
SQL> insert into teachings values('c501','bba1','p2','1jan2003','1jan2008');
SQL> select * from teachings;
SID CLASS PAPER FSESSION TSESSION
-------- --------------- -------------- -------------------- ---------------------
c101 bca2 p1 01-JAN-07 01-JAN-08
c102 bca2 p4 01-MAR-05 31-MAR-08
c201 bca1 p5 01-JAN-06 01-JAN-08
c301 bcom2 p6 01-AUG-07 01-AUG-08
c401 bcom1 p7 01-JUL-02 01-JUL-08
c501 bcom2 p5 01-SEP-03 01-SEP-08
c601 bsc1 p10 01-FEB-01 31-MAR-08
c701 bsc2 p10 01-MAR-07 31-MAR-08
Page 42 of 70
c601 bba2 p7 01-JUL-04 01-JUL-08
c501 bba1 p2 01-JAN-03 01-JAN-08
Using the following database
C)- list the names of the teachers teaching computer subject:
SQL> select sname from staffs where sid=(select sid from teachings where paperid =(select
paperid from subjects where subjects='computer'));
SNAME
---------------
rameshwara
D)- List all the names os and cities of all staff working in your college:
SQL> select sname, saddress from staffs where sid=(select sid from staffjoins where
cname='c1');
SNAME SADDRESS
--------------- ---------------
rajesha sec-2
E)- List the name of the cities of all staffs working in your colleges who earn
More than 15000:
SQL> select sname,saddress from staffs where sid =(select sid from staffjoins where cname
='c1' and salary>15000);
SNAME SADDRESS
--------------- ---------------
rajesha sec-2
Page 43 of 70
Assignment -5
Using the following database
Colleges (cname, city, address, phone, afdate)
Staffs ( sid, sname, saddress, contacts)
StaffJoins ( sid, cname, dept, DOJ, post, salary)
Teachings ( sid, class, paperid, fsession, tsession)
Subjects ( paperid, subject, paperno, papername)
a)find the staffs whose names starts with ‘M’ or ‘R’ ends with ‘A’ and / or 7
characters long:
SQL> select sname from staffs where sname like 'm_____%a' or sname like 'r____%a';
SNAME
---------------
rameshwara
manyata
b)find the staffs whose date of joining is 2005:
SQL> select sname from staffs where sid=(select sid from staffjoins where extract(year
from doj)=2005);
SNAME
---------------
n1
c)Modify the database so that staff N1 now works in C2 college.
SQL> update staffjoins set cname='c2' where sid=(select sid from staffs where sname='n1');
Page 44 of 70
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ------------ --------- ---------- ---------
c101 c3 computer 01-MAR-08 teacher 10000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 17000
c301 c2 science 01-APR-05 clerk 1000
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 10000
c701 c8 comerc 01-MAR-08 teacher 10000
c601 c9 maths 01-AUG-08 hod 11000
c501 c10 hindi 01-JUL-08 hod 11000
d)List the name of subject which t1 teaches in this session or all session:
SQL> select subjects from subjects where paperid=(select paperid from teachings where
(extract (year from fsession)=07 or fsession is not null) and sid=(select sid from staffs where
sname='t1'));
SUBJECTS
---------------
english
Page 45 of 70
Assignment -6
Using the following database
Colleges (cname, city, address, phone, afdate)
Staffs ( sid, sname, saddress, contacts)
StaffJoins ( sid, cname, dept, DOJ, post, salary)
Teachings ( sid, class, paperid, fsession, tsession)
Subjects ( paperid, subject, paperno, papername)
a)find the class that t1 do not teaches at present session:
SQL>select class from teachings where extract (year from fsession)<>07 and sid=(select sid from
staffs where sname='t1');
CLASS
----------
bca1
b. Find the college who have most number of staffs.
SQL>select cname , count(sid) from staffjoins group by cname having count(sid)>=2 order by
count(sid);
CNAME COUNT(SID)
---------- ---------------
c2 2
c. Find the staffs who earn a higher salary who earn greater than average
salary of theircollege.
SQL> select salary from staffjoins where cname like 'c2' and salary>(select avg(salary) from
staffjoins group by cname having cname like 'c2');
Page 46 of 70
SALARY
---------
1700
d. Find the colleges whose average salary is more than average salary of C2
SQL>select cname, avg(salary) from staffjoins group by cname having avg(salary)>(select
avg(salary) from staffjoins where cname='c2');
CNAME AVG(SALARY)
---------- -----------
c1 17000
c10 11000
c3 10000
c6 12000
c7 10000
c8 10000
c9 11000
e. Find the college that has the smallest payroll.
SQL> select cname from staffjoins where salary=(select min(salary) from staffjoins);
CNAME
--------
c2
c5
f. Find the colleges where the total salary is greater than the average salary of
all colleges.
SQL> select cname, sum(salary) from staffjoins group by cname having sum(salary)>(select
avg(sum(salary)) from staffjoins group by cname);
CNAME SUM(SALARY)
---------- -----------
Page 47 of 70
c1 17000
c2 18000
c6 12000
g. List maximum, average, minimum salary of each college
SQL> select cname, max(salary) "max salary", avg(salary) "avg salary", min(salary) "min
salary" from staffjoins group by cname;
CNAME MAX SALARY AVG SALARY MIN SALARY
---------- -------------------- --------------------- ------------------
c1 17000 17000 17000
c10 11000 11000 11000
c2 17000 9000 1000
c3 10000 10000 10000
c5 1000 1000 1000
c6 12000 12000 12000
c7 10000 10000 10000
c8 10000 10000 10000
c9 11000 11000 11000
Page 48 of 70
Assignment -7
Using the following database
Colleges (cname, city, address, phone, afdate)
Staffs ( sid, sname, saddress, contacts)
StaffJoins ( sid, cname, dept, DOJ, post, salary)
Teachings ( sid, class, paperid, fsession, tsession)
Subjects ( paperid, subject, paperno, papername)
a. Find the classes that T1 do not teach at present session.
SQL> select subjects from subjects where paperid=(select paperid from teachings where
(extract (year from fsession)=07 or fsession is not null) and sid=(select sid from staffs where
sname='t1'));
SUBJECTS
---------------
english
b. List the names of the teachers, departments teaching in more than one
departments.
SQL>select sname, dept from staffs, staffjoins where [Link]=[Link] and [Link]
in(select sid from staffjoins group by sid having count(sid)>1);
SNAME DEPT
--------------- ----------
t3 english
Page 49 of 70
t3 hindi
t4 hindi
t4 maths
c. Acquire details of staffs by name in a college or each college.
SQL> select [Link], sname, saddress, contacts, dept, doj, post, salary from staffs, staff
joins where [Link]=[Link] order by sname;
SID SNAME SADDRESS CONTACTS DEPT DOJ POST SALARY
----- --------------- --------------- ------------ ---------- ---------- --------- ---------- ---------
c103 manyata sec-9 993010509 maths 01-APR-07 teacher 17000
c301 n1 sec-11 997550509 science 01-APR-05 clerk 1000
c401 n2 sec-1 998550509 arts 09-MAY-04 clerk 1000
c102 rajesha sec-2 993010509 maths 01-APR-08 principal 17000
c101 rameshwara sec-6 998580509 computer 01-MAR-08 teacher 10000
c501 t3 sec-5 998570509 english 01-MAR-02 director 12000
c501 t3 sec-5 998570509 hindi 01-JUL-08 hod 11000
c601 t4 sec-7 998280509 hindi 12-APR-07 teacher 10000
c601 t4 sec-7 998285509 maths 01-AUG-08 hod 11000
c701 t5 sec-3 997285509 comerc 01-MAR-08 teacher 10000
d. Find the names of staff who earn more than each staff of C2 college.
SQL> select sname from staffs,staffjoins where [Link]=[Link] and salary>(select
max(salary) from staffjoins where cname like 'c2');
SNAME
---------------
rajesha
Page 50 of 70
t3
t4
t3
e. Give all principals a 10% rise in salary unless their salary becomes greater
than 20,000 in such case give 5% rise.
SQL> update staffjoins set salary=5salary*0.1 where(salary5salary*0.1)< 20000 and
post='teacher';
SQL> select * from staffjoins;
SID CNAME DEPT DOJ POST SALARY
----- ---------- ---------- --------- ---------- ---------
c101 c3 computer 01-MAR-08 teacher 1000
c102 c1 maths 01-APR-08 principal 17000
c103 c2 maths 01-APR-07 teacher 1700
c301 c2 science 01-APR-05 clerk 1000
c401 c5 arts 09-MAY-04 clerk 1000
c501 c6 english 01-MAR-02 director 12000
c601 c7 hindi 12-APR-07 teacher 1000
c701 c8 comerc 01-MAR-08 teacher 1000
c601 c9 maths 01-AUG-08 hod 11000
c501 c10 hindi 01-JUL-08 hod 11000
f. Find all staff who donot work in same cities as the colleges they work.
SQL> select sname from staffs s,colleges c,staffjoins j where [Link]=[Link] and [Link]=[Link] and
[Link]<>[Link];
SNAME
---------------
rameshwara
rajesha
manyata
Page 51 of 70
n1
n2
t3
t4
t5
t4
t3
g. List names of employees in ascending order according to salary who are
working in your college or all colleges.
SQL> Select [Link], [Link], [Link] from staffs st, staffjoins sj where [Link]=[Link] order by
[Link];
SID SNAME SALARY
----- --------------- ---------
c101 rameshwara 1000
c301 n1 1000
c601 t4 1000
c401 n2 1000
c701 t5 1000
c103 manyata 1700
c601 t4 11000
c501 t3 11000
c501 t3 12000
c102 rajesha 17000
Page 52 of 70
Assignment -8
Using the following database
Colleges (cname, city, address, phone, afdate)
Staffs ( sid, sname, saddress, contacts)
StaffJoins ( sid, cname, dept, DOJ, post, salary)
Teachings ( sid, class, paperid, fsession, tsession)
Subjects ( paperid, subject, paperno, papername)
a. Find the classes that T1 do not teach at present session.
SQL> select subjects from subjects where paperid=(select paperid from teachings where
(extract (year from fsession)=07 or fsession is not null) and sid=(select sid from staffs where
sname='t1'));
SUBJECTS
---------------
english
b. Create a view having fields sname, cname, dept, DOJ, and post
SQL> create view staffdetails as select sname,cname,dept,doj,post from staffs,staffjoins where
[Link]=[Link];SQL> select * from staffdetails;
SNAME CNAME DEPT DOJ POST
------------ -------------- --------- ----------- ---------------
rameshwara c3 computer 01-MAR-08 teacher
rajesha c1 maths 01-APR-08 principal
manyata c2 maths 01-APR-07 teacher
Page 53 of 70
n1 c2 science 01-APR-05 clerk
n2 c5 arts 09-MAY-04 clerk
t3 c6 english 01-MAR-02 director
t4 c7 hindi 12-APR-07 teacher
t5 c8 comerc 01-MAR-08 teacher
t4 c9 maths 01-AUG-08 hod
t3 c10 hindi 01-JUL-08 hod
c. Create a view consisting of cname, average salary and total salary of all
staff in that college.
SQL> create view college_sal as select cname,round(avg(salary),2)"Average",sum(salary)"Total"
from staffjoins group by cname;
SQL> select * from college_sal;
CNAME Average Total
---------- --------- ---------
c1 17000 17000
c10 11000 11000
c2 1350 2700
c3 1000 1000
c5 1000 1000
c6 12000 12000
c7 1000 1000
c8 1000 1000
c9 11000 11000
e. List the staff names of a department using above views.
SQL> select dept,cname,sname from staffdetails s where [Link]=dept;
DEPT CNAME SNAME
---------- ---------- ---------------
computer c3 rameshwara
maths c1 rajesha
maths c2 manyata
science c2 n1
Page 54 of 70
arts c5 n2
english c6 t3
hindi c7 t4
comerc c8 t5
maths c9 t4
hindi c10 t3
Assignment -9
Enrollment (enrollno, name, gender, DOB, address, phone)
Admission (admno, enrollno, course, yearsem, date, cname)
Colleges (cname, city, address, phone, afdate)
FeeStructure (course, yearsem, fee)
Payment (billno, admno, amount, pdate, purpose)
a. Create the above tables with the given specifications and constraints.
b. Insert about 10 rows as are appropriate to solve the following queries.
Create table:- Enrollment
SQL>create table enrollment(enrollno varchar2(10 ) primary key, name
varchar(10), gender varchar2(7),dob date, address varchar2(20),phone
number(10));
Create table:- Fees structure
SQL> create table feestructure(course varchar2(10), yearsem varchar2(10),
fee number(6), constraint feestructure primary key(course, yearsem));
Create table:- college
SQL> create table college(cname varchar2(10), city varchar2(10), address
varchar2(10),phone number(10), afdate date, constraint college primary key
(cname));
Create table :-admission
SQL>create table admission(admno number(10) primary key, enrollno references
enrollment,course varchar(10), yearsem varchar2(10), dob date, cname references
college,foregin key(course, yearsem) references feestructure);
Page 55 of 70
Create table:- payment
SQL> create table payment(billno number(5) primary key, admno references
admission, amount number(8), pdate date , purpose varchar2(15));
INSERT ROWS IN ENROLLMENT
SQL> insert into enrollment values('1001','khyati','female','6-nov-89','bhilai',9755721881);
SQL> insert into enrollment values('1002','nikita','female','15-april-89','durg',954213505);
SQL> insert into enrollment values('1003','jyoti','female','2-feb-90','bhilai',91789275);
SQL> insert into enrollment values('1004','anil','male','19-dec-88','charoda',9302972);
SQL> insert into enrollment values('1005','swati','female','8-dec-88','raipur',981447534);
SQL> insert into enrollment values('1006','manish','male','28-jul-87','bhilai',9893046469);
SQL> insert into enrollment values('1007','anand','male','05-dec-88','nehru nagar',9872344);
SQL> insert into enrollment values('1008','ruma','female','30-jan-88','bhilai',975576089);
SQL> insert into enrollment values('1009','kiran','female','9-sep-89','bhilai',989358786);
SQL> insert into enrollment values('1010','usha','female','20-april-88', 'durg',9755764634);
SQL> select * from enrollment;
ENROLLNO NAME GENDER DOB ADDRESS PHONE
---------- ---------- --------------- --------- -------------------- ---------------
1001 khyati female 06-NOV-89 bhilai 9755721881
1002 nikita female 15-APR-89 durg 954213505
1003 jyoti female 02-FEB-90 bhilai 91789275
1004 anil male 19-DEC-88 charoda 9302972
1005 swati female 08-DEC-88 raipur 981447534
1006 manish male 28-JUL-87 bhilai 9893046469
Page 56 of 70
1007 anand male 05-DEC-88 nehru nagar 9872344
1008 ruma female 30-JAN-88 bhilai 975576089
1009 kiran female 09-SEP-89 bhilai 989358786
1010 usha female 20-APR-88 durg 94567777899
INSERT ROWS IN FEESTRUCTURE:
SQL>insert into feestructure values('bca2','2009-2009',20000);
SQL>insert into feestructure values('bca3','2009-2009',21000);
SQL>insert into feestructure values('bca1','2009-2009',20000);
SQL>insert into feestructure values('bcom3','2009-2009',22000);
SQL>insert into feestructure values('bcom2','2007-2008',18000);
SQL>insert into feestructure values('bcom1','2006-2007',10000);
SQL>insert into feestructure values('bsc3','2008-2009',12000);
SQL>insert into feestructure values('bba3','2004-2005',8000);
SQL>insert into feestructure values('ba3','2004-2005',8000);
SQL>insert into feestructure values('bca3','2007-2008',22000);
SQL> select * from feestructure;
COURSE YEARSEM FEE
---------- ---------- ----------
bca2 2009-2009 20000
bca3 2009-2009 21000
bca1 2009-2009 20000
bcom3 2009-2009 22000
bcom2 2007-2008 18000
bcom1 2006-2007 10000
Page 57 of 70
bsc3 2008-2009 12000
bba3 2004-2005 8000
ba3 2004-2005 8000
bca3 2007-2008 22000
INSERT ROWS IN COLLEGE:-
SQL>insert into college values('shankara','bhilai','sec-6','2224567','19-jul-1990');
SQL>insert into college values('kalyan','durg','hudco','2673656','1-feb-1990');
SQL>insert into college values('shivam','bhilai','hudco','2673656','19-july-1989');
SQL>insert into college values('disha','bhilai','hudco','2673656','19-july-1998');
SQL>insert into college values('boysclg','durg','sec-1','2673656','21-feb-1998');
SQL>insert into college values('girlsclg','durg','sec-10','2673656','12-feb-1998');
SQL>insert into college values('Bit','camp','sec-10','2673656','12-march-1998');
SQL>insert into college values('science','raipur','sec-10','2673656','12-march-1998');
SQL>insert into college values('rungta','kohka','sec-2','2673656','12-april-1998');
SQL>insert into college values('dental','kohka','sec-2','2673656','1-aug-1988');
SQL> select * from college;
CNAME CITY ADDRESS PHONE AFDATE
---------- ---------- ---------- ---------- ---------
shankara bhilai sec-6 2224567 19-JUL-90
kalyan durg hudco 2673656 01-FEB-90
shivam bhilai hudco 2673656 19-JUL-89
disha bhilai hudco 2673656 19-JUL-98
boysclg durg sec-1 2673656 21-FEB-98
Page 58 of 70
girlsclg durg sec-10 2673656 12-FEB-98
Bit camp sec-10 2673656 12-MAR-98
science raipur sec-10 2673132 12-MAR-98
rungta kohka sec-2 26735566 12-APR-98
dental kohka sec-2 2673656 01-AUG-88
INSERT ROWS IN ADMISSION:-
SQL>insert into admission values(1,1001,’bca2’,’2009-2009’,’20-jun-09’,’shankara’);
SQL>insert into admission values(2,1002,’bca3’,’2009-2009’, 05-AUG-08’,’kalyan’);
SQL>insert into admission values(3,1003,’bcom2’,’2007-2008’,’ 18-SEP-07,’ shivam’);
SQL>insert into admission values(4,1004,’bba3’,’2004-2005’, 14-JUN-05’,’ disha’);
SQL>insert into admission values(5,1005,’ba3’,’2004-2005’,’ 20-APR-04’,’ girlsclg’);
SQL>insert into admission values(6,1006,’bcom1’,’2006-2007’,’ 15-AUG-07’,’ boysclg’);
SQL>insert into admission values(7,1007,’bcom3’,’2009-2009’,’ 13-JUL-08’,’ Bit’);
SQL>insert into admission values(8,1008,’bca1’,’2009-2009’,’ 23-FEB-09’,’ rungta’);
SQL>insert into admission values(9,1009,’bsc3’,’2008-2009’,’ 20-JAN-09’,’ science’);
SQL>insert into admission values(10,1010,’bcom1’,’2006-2007’,’ 20-FEB-07’,’ dental’);
SQL> select * from admissions;
ADMNO ENROLLNO COURSE YEARSEM DOA CNAME
------------- ------------- ------------- --------------- --------- --------------------
1 1001 bca2 2009-2009 20-JUN-09 shankara
2 1002 bca3 2009-2009 05-AUG-08 kalyan
3 1003 bcom2 2007-2008 18-SEP-07 shivam
4 1004 bba3 2004-2005 14-JUN-05 disha
Page 59 of 70
5 1005 ba3 2004-2005 20-APR-04 girlsclg
6 1006 bcom1 2006-2007 15-AUG-07 boysclg
7 1007 bcom3 2009-2009 13-JUL-08 Bit
8 1008 bca1 2009-2009 23-FEB-09 rungta
9 1009 bsc3 2008-2009 20-JAN-09 science
10 1010 bcom1 2006-2007 20-FEB-07 dental
INSERT ROWS IN PAYMENT:-
SQL>insert into payment values(1,1,10000,’20-jun-08’,’admn fee’);
SQL>insert into payment values(2,2,10500,’ 17-JUN-08’,’tution fee’);
SQL>insert into payment values(3,3,20000,’ 08-JUL-08’,’ tution fee’);
SQL>insert into payment values(4,4,11000,’ 05-AUG-08’,’admn fee’);
SQL>insert into payment values(5,5,9000,’ 05-JUN-07’,’admn fee’);
SQL>insert into payment values(6,6,10000,’ 06-SEP-06’,’ tution fee’);
SQL>insert into payment values(7,7,12000,’ 05-MAY-08’,’ tution fee’);
SQL>insert into payment values(8,8,8000,’ 09-SEP-04’,’ tution fee’);
SQL>insert into payment values(9,9,5000,’ 05-JUL-08’,’admn fee’);
SQL>insert into payment values(10,10,11000,’ 06-JUN-07’,’admn fee’);
SQL> select * from payment;
BILLNO ADMNO AMOUNT PDATE PURPOSE
------------- -------------- --------------- ------------- ---------------
1 1 10000 20-JUN-08 admn fee
2 2 10500 17-JUN-08 tution fee
3 3 20000 08-JUL-08 tution fee
4 4 11000 05-AUG-08 admn fee
Page 60 of 70
5 5 9000 05-JUN-07 admn fee
6 6 10000 06-SEP-06 tution fee
7 7 12000 05-MAY-08 tution fee
8 8 8000 09-SEP-04 tution fee
9 9 5000 05-JUL-08 admn fee
10 10 11000 06-JUN-07 admn fee
C). Get detail of students who took admission in Bhilai colleges.
SQL> select * from enrollment where enrollno in(select enrollno from admissions where cname
in(select cname from college where city='bhilai'));
ENROLLNO NAME GENDER DOB ADDRESS PHONE
---------- ---------- ------- --------- -------------------- ---------
1001 khyati female 06-NOV-89 bhilai 975667009
1003 jyoti female 02-FEB-90 bhilai 917892750
1004 anil male 19-DEC-88 charoda 930297872
d. Calculate the total amount of fees collected in this session
i) by your college ii) by each college iii) by all colleges
i) by your college
SQL select sum (p. amount) "Total fee" from payment p, admissions a where [Link]=[Link]
and [Link] like '2008-2009' and [Link] like 'shankara';
Total fee
----------
10000
Page 61 of 70
ii) by all college
SQL >select sum([Link]) "Total fee" from payment p,admissions a where [Link]=[Link]
and [Link] like '2008-2009';
Total fee
---------
5000
Assignment -10
Enrollment (enrollno, name, gender, DOB, address, phone)
Admission (admno, enrollno, course, yearsem, date, cname)
Colleges (cname, city, address, phone, afdate)
FeeStructure (course, yearsem, fee)
Payment (billno, admno, amount, pdate, purpose)
a. List the students who have not payed full fee
i) in your college ii) in all colleges
i ) in your college
ii) SQL> select [Link] from enrollment e, admissions a, feestructure f, payment p where
[Link]=[Link] and [Link]=[Link] and [Link]=[Link] and
[Link]=[Link] and [Link]> [Link] and [Link]='shankara';
iii) NAME
iv) ----------
v) Khyati
ii) in other college
Page 62 of 70
SQL> select [Link] from enrollment e, admissions a, feestructure f, payment p where enrollno =
[Link] and [Link]=[Link] and [Link]=[Link] and [Link]=[Link] and [Link] >
[Link];
NAME
----------
khyati
nikita
anand
ruma
kiran
b. List the students in the session who are not in the colleges in the same
city as they live in.
SQL> select [Link] from enrollment e, admissions a, college c where [Link]=[Link]
and [Link]=[Link] and [Link]<> [Link] and [Link]='2008-2009’;
NAME
----------
kiran
c. List the students in colleges in your city and also live in your city.
SQL> select [Link] from enrollment e, admissions a, college c where [Link]=[Link] and
[Link]=[Link] and [Link]= [Link];
NAME
----------
khyati
nikita
Page 63 of 70
jyoti
Assignment -11
Subjects ( paperid, subject, paper, papername)
Test (paperid, date, time, max, min)
Score (rollno, paperid, marks, attendence)
Students (admno, rollno, class, yearsem)
a. Create the above tables with the given specifications and constraints.
b. Insert about 10 rows as are appropriate to solve the following queries.
Ques A) ::--- Create the tables with the given specifications and
constraints.
Create table:-Subject
SQL> create table subject(paperid varchar2(10) primary key, subjects
varchar2(20),paper varchar2(10), papername varchar2(15));
Create table:-Test
SQL>create table test (paperid references subject, doe date, time
varchar2(10),max varchar2(5), min varchar2(5));
Page 64 of 70
Create table:-Score
SQL>create table score(rollno varchar2(10) primary key, paperid references
subject, marks number(5), attendence char(1) check(attendence='a' or
attendence='p' or attendence='A' or attendence='P'));
Create table:-Students
SQL> create table students(admno varchar2(5) primary key, rollno references
score, class varchar2(10), yearsem varchar2(10));
INSERT ROWS INTO SUBJECT:
SQL> insert into subject values('p1','computers','101','dbms');
SQL> insert into subject values('p2','arts','102',' dance ');
SQL>insert into subject values('p3',' finearts ','103','sketching');
SQL> insert into subject values('p4','maths','104','calculus');
SQL> insert into subject values('p5','english','105','foundation');
SQL> insert into subject values('p6','economics','106','statitics');
SQL> insert into subject values('p7','businessstds','107','accounts');
SQL> insert into subject values('p8','hindi','108','mainreader');
SQL> insert into subject values('p9','social science','109','history');
SQL> insert into subject values('p10','maths','110','physics');
SQL> select * from subject;
PAPER SUBJECTS PAPER PAPERNAME
----- --------------- ----------- -------------------
p1 computer 101 dbms
p2 arts 102 dance
Page 65 of 70
p3 finearts 103 sketching
p4 maths 104 calculus
p5 enghish 105 foundation
p6 economics 106 statsistics
p7 bussines stds 107 accounts
p8 hindi 108 mainreader
p9 social studies 109 history
p10 science 110 physics
INSERT ROWS INTO TEST:
SQL>insert into test values(‘1‘,’01-MAR-09 11 am ‘,’100‘,’40’);
SQL>insert into test values('2’,’05-MAR-09 11 am’,’50’,’20');
SQL>insert into test values('3’,’07-MAR-09 11 am’,’50’,’20');
SQL>insert into test values('4’,’10-MAR-09 11 am’,’50’,’20');
SQL>insert into test values('5’,’12-MAR-09 11 am ‘,’100 ‘,’40');
SQL>insert into test values('6’,’14-MAR-09 11 am’,’100 ‘,’40');
SQL>insert into test values('7’,’17-MAR-09 11 am’,’100’,’40');
SQL>insert into test values('8’,’20-MAR-09 11 am’,’50’,’20');
SQL>insert into test values('9’,’22-MAR-09 11 am’,’50’,’20');
SQL>insert into test values('10’,’24-MAR-09 11 am’,’100’,’40');
SQL> select * from test;
PAPER DOT TIME MAX MIN
----- --------- ---------- --------- -------------- ----------
1 01-MAR-09 11 am 100 40
2 05-MAR-09 11 am 50 20
Page 66 of 70
3 07-MAR-09 11 am 50 20
4 10-MAR-09 11 am 50 20
5 12-MAR-09 11 am 100 40
6 14-MAR-09 11 am 100 40
7 17-MAR-09 11 am 100 40
8 20-MAR-09 11 am 50 20
9 22-MAR-09 11 am 50 20
10 24-MAR-09 11 am 100 40
INSERT ROWS INTO SCORE:
SQL>insert into score values(' r001‘,’1’,’81’,’ present');
SQL> insert into score values(' r002’,’2 ‘,’ ‘,’absent');
SQL>insert into score values(' r003’,’3’,’50’,’ present');
SQL>insert into score values(' r004’,’4’,’62 ‘,’present');
SQL>insert into score values(' r005’,’5’,’30 ‘,’present');
SQL>insert into score values(' r006’,’6’,’ ‘,’absent');
SQL>insert into score values(' r007’,’7’,’ ‘,’77’,’present');
SQL>insert into score values(' r008‘,’8’,’ ‘,’20’,’ present');
SQL>insert into score values(' r009‘,’9‘,’80’,’ present');
SQL>insert into score values(' r010’,’10‘,’88‘,’present');
SQL> select * from score;
ROLLNO PAPER MARKS ATTENDANCE
--------- --------- ------------ --------------------
r001 1 81 present
r002 2 absent
r003 3 50 present
Page 67 of 70
r004 4 62 present
r005 5 30 present
r006 6 absent
r007 7 77 present
r008 8 20 present
r009 9 80 present
r010 10 88 present
INSERT ROWS INTO STUDENTS:
SQL>insert into students values('01','101','bca2','2008-2009');
SQL>insert into students values('2','102','bca2','2008-2009');
SQL>insert into students values('3','103','bca2','2008-2009');
SQL>insert into students values('4','104','bca2','2008-2009');
SQL>insert into students values('5','105','bca2','2008-2009');
SQL>insert into students values('6','106','bca2','2008-2009');
SQL>insert into students values('7','107','bca2','2008-2009');
SQL>insert into students values('8','108','bca2','2008-2009');
SQL>insert into students values('9','109','bca2','2008-2009');
SQL>insert into students values('10','110','bca2','2008-2009');
SQL> select * from students;
ADMNO ROLLNO CLASS YEAR SEM
------------- -------------- ----------- ---------------
a001 r001 BCA-I 2ndsem
a002 r002 BCA-II 1stsem
Page 68 of 70
a003 r003 BCA-III 2ndsem
a004 r004 BCA-II 2ndsem
a005 r005 BCA-II 1stsem
a006 r006 BCA-I 1stsem
a007 r007 BCA-III 1stsem
a008 r008 BCA-II 2ndsem
a009 r009 BCA-III 1stsem
a010 r010 BCA-II 1stsem
c. List the students who were present in a paper of a subject.
SQL> select [Link] from students, score where ([Link]=[Link] and
attendance='present');
ROLLNO
-----
r001
r003
r004
r005
r007
r008
r009
r010
D. List all roll numbers who have passed in first division.
SQL> select rollno from score where marks>=60;
ROLLNO
Page 69 of 70
-----
r001
r004
r007
r009
r010
e. List all students in MCA-II who have scored higher than average
i) in your college ii) in every college
SQL>select [Link],marks from students, score where
[Link]=[Link] and marks>(select avg(marks) from score,students where
class='MCA-II' and [Link]=[Link]);
ROLLNO MARKS
----- ---------
r001 81
r004 62
r007 77
r009 80
r010 88
f. List the highest score, average and minimum score in MCA-II
i) in your college ii) in every college
SQL> select max(marks), avg(marks), min(marks) from score, students
Page 70 of 70
where [Link]=[Link] and class='MCA-II' group by class;
MAX(MARKS) AVG(MARKS) MIN(MARKS)
---------- ---------- ----------
88 50 22