Dbms Lab Exp4
Dbms Lab Exp4
Program - 4
Aim: Introduce concepts of PLSQL and usage on the table.
Program: Program: Consider the schema for College Database:
STUDENT(USN, SName, Address, Phone, Gender)
SEMSEC(SSID, Sem, Sec)
CLASS(USN, SSID)
COURSE(Subcode, Title, Sem, Credits)
IAMARKS(USN, Subcode, SSID, Test1, Test2, Test3, FinalIA)
Write SQL queries to
i. List all the student details studying in fourth semester ‘C’ section.
ii. Compute the total number of male and female students in each semester and in each
section.
iii. Create a view of Test1 marks of student USN ‘1BI15CS101’ in all Courses.
iv. Calculate the FinalIA (average of best two test marks) and update the corresponding table
for all students.
v. Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.
Schema Diagram:
Output
Output
(ii)Write SQL queries to compute the total number of male and female students in each
semester and in each section .
Query: select sem,sec,gender,count(*) as count from STUDENT s, SEMSEC sc, CLASS c
where s.usn=c.usn and sc.ssid=c.ssid
group by(sem,sec,gender);
Output:
(iii)Write SQL queries to create a view of Test1 marks of student USN ‘1BI17CS101’ in all
subjects.
Query: create view test1 as ( select usn,test1,subcode from iamarks where usn=’CS101’ );
select * from test1;
Output:
(iv)Write SQL queries to calculate the FinalIA (average of best two test marks) and update
the corresponding table for all students.
Query(a): create view average_finder1 as (select usn,subcode,greatest(test1,test2,test3) as
highest, case when test1<greatest(test1,test2,test3) and test1>least(test1,test2,test3)
then test1 when test2<greatest(test1,test2,test3) and test2>least(test1,test2,test3)
then test2 else test3 end as second_highest from iamarks );
Output:
select * from average_finder1;
Query(b): update IAMARKS a set finalia = ( select (highest+second_highest)/2 from
average_finder1 where a.usn =usn and a.subcode= subcode);
Output:
select * from iamarks;
(v) Categorize students based on the following criterion:
If FinalIA = 17 to 20 then CAT = ‘Outstanding’
If FinalIA = 12 to 16 then CAT = ‘Average’
If FinalIA< 12 then CAT = ‘Weak’
Give these details only for 8th semester A, B, and C section students.
Query: select s.usn,s.sname,s.address,s.phone,s.gender,
(case when ia.finalia between 17 and 20 then 'outstanding'
when ia.finalia between 12 and 16 then 'average'
else 'weak' end) as CATEGORY
from student s, semsec ss, iamarks ia, course c
where s.usn = ia.usn and ss.ssid = ia.ssid and c.subcode = ia.subcode and c.sem = 8;
Output: