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";

5 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. iii) part shows error
    it says Unknown column 'Marks' in 'having clause'

    ReplyDelete
    Replies
    1. i did try with where clause what will be the correct output though?
      coz i'm not sure about mine

      Delete
    2. SELECT Name, Class, COUNT(*) FROM Student
      GROUP BY Class HAVING Marks > 450;

      This query is working in my pc.
      So, Please tell me error .

      Delete
  2. Tell me the error shown in your SQL

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post