Professional Documents
Culture Documents
Raghav Dbms Ex - 1c
Raghav Dbms Ex - 1c
Raghav Dbms Ex - 1c
Create a Student table with the attributes Rollno, Sname, Passport Number, Department
code, Age, CGPA, and Club Membership ID. Also add suitable constraints to Student table
Code: create table student(
rollno int primary key,
sname varchar(50),
passport_no int unique,
dept_code int,
age int,
cgpa float,
club_id int
);
insert into student values(1,'vishal',12345,20,18,9.18,14);
insert into student values(2,'sengathir',54324,63,20,9.09,94);
insert into student values(4,'murugavel',24523,23,72,9.3,89);
insert into student values(3,'kavin',24535,26,34,9.21,43);
Que 1: Fetch Rollno and Sname from student table and display StudName instead of Sname
in the output
Code:
Output:
ROLL STUDNA
NO ME
1 vishal
2 sengathir
murugav
4
el
3 kavin
Que 2: Display CGPAChanged instead of CGPA with additionally provide 0.5 if the CGPA of
select rollno, case when cgpa in(5.9,6.9,7.9,8.9) then cgpa +0.5 end as CgpaChanged from student;
Output:
ROLL CGPACHANG
NO ED
1 -
2 -
4 -
3 -
Que 3: Display all students that starts with ‘M' or 'V', ends with ‘i’ and are at least 6
characters in Length
Code:
select sname from student where (sname like 'M%' or sname like 'V%') and sname like '%i' and
length(sname)>=6;
Que 4: Selects all students with a Name that have "a" in the second position or the name
contains any one of the vowels
Code:
select sname from student where sname like '_a' or sname like '%a' or sname like '%e%' or sname
like '%i%' or sname like '%o%' or sname like '%u%';
Output:
SNAME
vishal
sengath
ir
muruga
vel
kavin
Que 5: Display student roll number and name of the student with a Name that should NOT start
Code:
Output:
ROLL
SNAME
NO
1 vishal
sengath
2
ir
muruga
4
vel
3 kavin
Que 6: Find the name of the students who are not having passport number and display the
Code:
Output:
SNA
ME
adf
Que 7: Find the roll no and name of the student who are having Club Membership ID
Code:
Output:
ROLL
SNAME
NO
1 vishal
sengath
2
ir
3 kavin
5 adf
Que 8: Add three more columns such as part time student, part time employee and Full time
student to the student table (Note: Update the existing records; e.g.: if the part time
student column is set to 1 then it means that the student is studying part time)
Code:
Output:
A
ROLL PASSPORT_ DEPT_CO CG CLUB PTS PTE FTS
SNAME G
NO NO DE PA _ID TU MP TU
E
1 9.1
1 vishal 12345 20 14 0 0 0
8 8
sengath 2 9.0
2 54324 63 94 0 0 0
ir 0 9
muruga 7
4 24523 23 9.3 89 0 0 0
vel 2
3 9.2
3 kavin 24535 26 43 0 0 0
4 1
3 9.2
5 adf - 26 43 0
4 1
with Sid, name and phone number from the table student
Code:
create table stu_ptemp as select rollno as Sid, sname as name, passport_no from student where
ptemp=1;
create table stu_ftst as select rollno as Sid, sname as name, passport_no from student where
ftstu=1;
Output:Table created.
Table created.
Table created.
Que 10: Display Maximum, minimum and average CGPA of students with name Max_CGPA,
Code:
Output:
Que 11: Display total number of students with the name “Tot_Stud”
Code:
Output:
no data found
SNA COUNT
ME (*)
visha
1
l
Output:
COUNT(UNIQUEA
Que 13: Retrieve and compute the summation of total age among students from the Students table.
Output:
SUM(A
GE)
178
Output:
DEPT_CO
SNAME
DE
sengath
63
ir
vishal 20
muruga
23
vel
adf 26
kavin 26
Que 15: Based on each department, display average CGPA obtained by the students
Output:
AVG(CG DEPT_CO
SNAME
PA) DE
sengath
9.09 63
ir
9.18 vishal 20
muruga
9.3 23
vel
9.21 kavin 26
Output:
AVG(CG
PA)
9.18
Que 17: Fetch the department name and number of students of those departments that have more
than 4 students
Code: select dept_code, sname from student group by dept_code, sname having count(*)>4;
Que 18: Find the name of the student who are studying full time and working part time(allow
duplication)
Que 19: Find the name of the student who are studying part time but not working part time
Output:
SNAME
sgd
vishal
sengath
ir
muruga
vel
kavin
adf
time(restrict duplication)
Code: select distinct sname from student where ptstu=1 union select distinct sname from student
where ptemp=1;
Output:
SfE
fdg