Q. Write SQL queries for (i) to (iv), which are based on the table: STUDENT given in the question 4(g):
(i) To display the records from table student in alphabetical order as per the name of the student.
(ii) To display Class, Dob and City whose marks is between 450 and 551.
(iii) To display Name, Class and total number of students who have secured more than 450 marks, class wise.
(iv) To increase marks of all students by 20 whose class is "XII".
Answer =
(i)
SELECT * FROM Student ORDER BY Name;
(ii)
SELECT Class, DOB, City FROM Student
WHERE Marks BETWEEN 450 AND 551;
OR
SELECT Class, DOB, City FROM Student
WHERE Marks >= 450 AND Marks <= 551 ;
(iii)
SELECT Name, Class, COUNT(*) FROM Student
GROUP BY Class HAVING Marks > 450;
(iv)
UPDATE Student SET Marks = Marks + 20 WHERE Class = "XII";
iii) part shows error
ReplyDeleteit says Unknown column 'Marks' in 'having clause'
Try it by where clause .
Deletei did try with where clause what will be the correct output though?
Deletecoz i'm not sure about mine
SELECT Name, Class, COUNT(*) FROM Student
DeleteGROUP BY Class HAVING Marks > 450;
This query is working in my pc.
So, Please tell me error .
Tell me the error shown in your SQL
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )