Module4 RA
Module4 RA
Studen
t course Stu_crs
PK PK FK FK
cnam
regno sname cgpa ccode e credits regno ccode
shivra CSE200 CSE200
101 m 9.7 4 DBMS 4 101 4
CSE200 CSE200
102 surya 9.5 3 DS 4 102 4
CSE300 CSE200
103 pranay 9.9 2 IWP 4 103 4
SWE30 DBM CSE200
104 sadhun 9.5 05 S 3 104 4
CSE200
105 kumar 9.4 105 4
CSE200
104 3
CSE200
105 3
RA and SQL
Select (Row) σ
1. List the name of the student with cgpa
Select student details
Select * from student;
σ (course)
4. List the students with 9.5 and the name ends with n
Select * from student where cgpa=9.5 and name like “%n”;
σ cgpa=9.5 ˄name like %n (student )
Student
PK
regno sname cgpa
101 shivram 9.7
102 surya 9.5
103 pranay 9.9
104 sadhun 9.5
105 kumar 9.4
2. List the ccode with name of the courses which has 4 credits
Select cname from course where credit=4;
∏ccode ,cname ¿ ¿
Aggregation(§)
Order:
Select
From
Where
Group by
Having
Studen
t course Stu_crs
PK PK FK FK
cnam
regno sname cgpa ccode e credits regno ccode
shivra CSE200 CSE200
101 m 9.7 4 DBMS 4 101 4
CSE200 CSE200
102 surya 9.5 3 DS 4 102 4
CSE300 CSE200
103 pranay 9.9 2 IWP 4 103 4
SWE300 CSE200
104 sadhun 9.5 5 DBMS 3 104 4
CSE200
105 kumar 9.4 105 4
CSE200
104 3
CSE200
105 3
Group by
5. List the number of courses for each credit
select credits, count(ccode) from course group by credits;
❑credits §count (ccode ), credits ( course )
Stu_crs
FK FK
regno ccode
101 CSE2004
102 CSE2004
103 CSE2004
104 CSE2004
105 CSE2004
104 CSE2003
105 CSE2003
101 1
102 1
103 1
104 2
105 2
select count(ccode), regno from stu_crs group by regno;
❑regno §count ( ccode ) ,regno ( stucrs )
Stu_crs
FK FK
regno ccode
101 CSE2004
102 CSE2004
103 CSE2004
104 CSE2004
105 CSE2004
104 CSE2003
105 CSE2003
101 1
102 1
103 1
104 2
105 2
104 2
105 2
Having – condition for aggregation function
8. List the number of courses registered by each student if, the count of
the courses is greater than one
select count(ccode), regno
from stu_crs
group by regno
having count(ccode)>1;
❑regno §count ( ccode ) ,regno (σ count (ccode )>1 ( stucrs ) )
9. List the number of courses registered by each student except 105 if,
the count of the courses is greater than one
select count(ccode), regno
from stu_crs
where regno<>105
group by regno
having count(ccode)>1;
❑regno §count ( ccode ) ,regno (σ count (ccode )>1 ,regno ≠105 ( stucrs ) )