You are on page 1of 2

Exercises

Table list ID Name Surname FlatHave FlatWant Goregaon Andheri Dadar Goregaon Andheri Sion Parle Dadar 1 Shantanu Oak 2 Shantanu Oak 3 Shantanu Oak 4 Ram 5 Shyam 6 Ram 7 Samir 8 Ram Joshi Sharma Naik Shah Joshi

9 Shyam Sharma Dadar Exercise I - Questions


Who has a flat in "Goreagon" and who wants to buy one? Who has a flat in "Parle" and who wants to buy one? Where does "Shantanu Oak" own the flats and where does he want to buy one? How many entries have been recorded so far? How many flats are there for sale? What are the names of our clients? How many clients do we have? List the customers whose name start with "S"? Rearrange the list Alphabetically sorted.

Table grades ID Name Math Physics Literature 1 John 68 2 Jim 3 Bill 96 65 37 89 12 54 92 57

4 Jeri 69 25 82 Exercise II - Questions


A list of all students who scored over 90 on his or her math paper? A list of all students who scored more than 85 in all subjects? Declare Results: Print the results of all students with result column. Find out total marks of all the students. What are the average marks of the class for each subject? What are the minimum marks in Math? What are the maximum marks in Math? Who got the highest marks in Math?

Exercise III Table Student

(i)Write the SQL command to create the above table with constraints. (ii) Insert 2 records with relevant information, in the table student (iii) Display all the records of the table Student. (iv) Delete the Student Whose Roll no is 100. (v) Change the Stream of Student to Computer Whose Roll no. is 536. (vi) Add one column email of data type VARCHAR and size 30 to the table Student. (vii) View structure of the table created by you. (viii) Drop the column Grade from the table Student. (ix) Drop the table student (x) Make the all changes permanently.

Exercise I - Answers

select * from list where FlatHave = "Goregaon" or FlatWant = "Goregaon" select * from list where FlatHave = "Parle" or FlatWant = "Parle" select * from list where Name = "Shantanu" and Surname = "Oak" select count(*) from list select count(FlatHave) from list where FlatHave is not null select distinct Name, Surname from list select count(distinct Name, surname) from list select * from list where Name like "S%" select Surname, Name, FlatHave, FlatWant from list order by Name

Exercise II - Answers Note: many problems have more than one correct solution.

SELECT * FROM grades WHERE math > 90 SELECT name FROM grades WHERE math > 85 AND physics > 85 AND literature > 85 SELECT *, IF( (math <= 35 OR physics <= 35 OR literature <= 35), 'fail', 'pass') AS result FROM grades ORDER BY result DESC SELECT name, math+physics+literature FROM grades SELECT AVG(math), AVG(physics), AVG(literature) FROM grades SELECT MIN(math) FROM grades SELECT MAX(math) FROM grades SELECT * FROM students ORDER BY math DESC LIMIT 1

Exercise III Answers


(i) create table student(Roll_No integer(4) primary key, Name varchar(20) NOT NULL, Stipend integer(7) Check Stipend>0, Stream varchar(15) NOT NULL,Grade varchar(1)); (ii) (a) insert into Student values(100,Vishal Mishra,1000, Science,A); (b) insert into Student values(101,Arvind Verma,2000, Science,A); (iii) select * from student; (iv) delete from Student where Roll_No=100; (v) update Student set Stream=Computer where Roll_No=536; (vi) alter table Student add(email varchar(30)); (vii) desc[ribe] Student; (viii) Alter table student drop grade; (ix) Drop table Student; (x) commit;

You might also like