You are on page 1of 7

ALL QUERIES ARE BASED ON THE RELATION

STUDENT

Table: STUDENT

No. Name Stipend Stream AvgMark Grade Class


1 Karan 400.00 Medical 78.5 B 12B
2 Divakar 450.00 Commerce 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12C
4 Arun 350.00 Humanities 73.1 B 12C
5 Sabina 500.00 Nonmedical 90.6 A 11A
6 John 400.00 Medical 75.4 B 12B
7 Robert 250.00 Humanities 64.4 C 11A
8 Rubina 450.00 Nonmedical 88.5 A 12A
9 Vikash 500.00 Nonmedical 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C
QUESTION 1 :- Create a table STUDENT containing 6 columns No,
Name,Stipend,Stream,AvgMark,Grade.

QUERY :- CREATE TABLE student


(
No. number PRIMARY KEY,
Name char(20) NOT NULL,
Stipend number(4,2),
Stream char(15) NOT NULL,
AvgMark number,
Grade char(2)
);

OUTPUT :-

Table: STUDENT

No. Name Stipend Stream AvgMark Grade

QUESTION 2 :- Add a column Class in table STUDENT.

QUERY :- ALTER TABLE student


ADD Class char(5);

OUTPUT :-

Table: STUDENT

No. Name Stipend Stream AvgMark Grade Class


QUESTION 3 :- Insert a row into the relation STUDENT.

QUERY :- INSERT INTO student


VALUES (1,”Karan”, 400.00,”Medical”, 78.5,’B’,”12B”);

OUTPUT :-
Table: STUDENT

No. Name Stipend Stream AvgMark Grade Class


1 Karan 400.00 Medical 78.5 B 12B

QUESTION 4 :- Select the Nonmedical students from table STUDENT.

QUERY :- SELECT Name


FROM student
WHERE Stream=”Nonmedical” ;

OUTPUT :-

Name
Sabina
Rubina
Vikash

QUESTION 5 :- List the names of those students who are in class 12


Sorted by Stipend in descending order.

QUERY :- SELECT Name FROM student


WHERE Class LIKE “12%” ORDER BY Stipend DESC;
OUTPUT :-

Name
Vikash
Rubina
Karan
John
Arun
Divya
Mohan
QUESTION 6 :- Display a report,listing names,Stipend,Stream and
Amount of Stipend received in a year assuming that
this Stipend is paid every month.

QUERY :- SELECT Name,Stipend,Stream,Stipend * 12


FROM student;

OUTPUT :-

Name Stipend Stream Stipend * 12


Karan 78.5 Medical 942
Divakar 89.2 Commerce 1070.4
Divya 68.6 Commerce 823.2
Arun 73.1 Humanities 877.2
Sabina 90.6 Nonmedical 1087.2
John 75.4 Medical 904.8
Robert 64.4 Humanities 772.8
Rubina 88.5 Nonmedical 1062
Vikash 92.0 Nonmedical 1104
Mohan 67.5 Commerce 810

QUESTION 7 :- Count the no. of student whose grade is ‘A’.

QUERY :- SELECT count(Grade)


FROM student
WHERE Grade =’A’;
OUTPUT :-

count(Grade)
4

QUESTION 8 :- Show streams available for students.

QUERY :- SELECT DISTINCT Stream


FROM student;

OUTPUT :-

Stream
Medical
Commerce
Humanities
Nonmedical

QUESTION 9 :- Show the names of those students whose AvgMark is


between 80 and 90 Sorted in ascending order by their
marks.

QUERY :- SELECT Name


FROM Student
WHERE AvgMark BETWEEN 80.0 AND 90.0
ORDER BY AvgMark;

OUTPUT :-

Name
Rubina
Divakar

QUESTION 10 :- Display the names of those students whose Grade is


‘A’ and ‘B’.

QUERY :- SELECT Name


FROM Student
WHERE Grade=’A’ AND Grade =’B’;
OUTPUT :-

Name
Divakar
Sabina
Rubina
Vikash
Karan
Arjun
John
QUESTION 11 :- Show the name, stipend of those students who are in
Medical, Humanities, Commerce Stream.

QUERY :- SELECT Name,Stipend


FROM student
WHERE Stream IN(‘Medical’ , ’Humanities’ ,
’Commerce’);

OUTPUT :-

Name Stipend
Karan 78.5
Divakar 89.2
Divya 68.6
Arun 73.1
John 75.4
Robert 64.4
Mohan 67.5

QUESTION 12 :- Display the names of the students with their Stream


whose grade is not ‘C’ and have maximum Stipend.

QUERY :- SELECT Name,Stream


FROM student
WHERE Grade <> ‘C’ and stipend=max(stipend);

OUTPUT :-

Name Stream
Sabina Nonmedical
Vikash Nonmedical
QUESTION 13 :- Show all the data of students whose names ends
with “bina”.
QUERY :- SELECT *
FROM student
WHERE Name LIKE “%bina”;

OUPUT :-

No. Name Stipend Stream AvgMark Grade Class


5 Sabina 500.00 Nonmedical 90.6 A 11A
8 Rubina 450.00 Nonmedical 88.5 A 12A

QUESTION 14 :- Display the average Stipend of student where class


is ‘12A’.

QUERY :- SELECT avg(Stipend)


FROM student
WHERE Class=’12A’;

OUTPUT :-

avg(Stipend)
475.00

QUESTION 15 :- Select all the data of those students whose stream


is not Medical.

QUERY :- SELECT *
FROM student
WHERE Stream <> Medical;

OUTPUT :-

NO. Name Stipend Stream AvgMark Grade Class


2 Divakar 450.00 Commerce 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12C
4 Arun 350.00 Humanities 73.1 B 12C
5 Sabina 500.00 Nonmedical 90.6 A 11A
7 Robert 250.00 Humanities 64.4 C 11A
8 Rubina 450.00 Nonmedical 88.5 A 12A
9 Vikash 500.00 Nonmedical 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C

You might also like