Skip to content
Question
Q.

Consider the following table School-data:

Table : School-data

Adm-noNameGradeClubMarksGender
20150001Sargam Singh12STEM86Male
20140212Alok Kumar10SPACE75Male
20090234Mohit Gaur11SPACE84Male
20130216Romil Malik10READER91Male
20190227Tanvi Batra11STEM70Female
20120200Nomita Ranjan12STEM64Female

Write SQL queries for the following: (i) Display the average Marks secured by each Gender. (ii) Display the minimum Marks secured by the students of Grade 10. (iii) Display the total number of students in each Club where number of students are more than 1. OR (Option for Part (iii) only) (iii) Display the maximum and minimum marks secured by each gender.

CBSECBSE Class XII Board 2023Subjective· 4mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): AVG(Marks) GROUP BY Gender; MIN(Marks) WHERE Grade=10 (=75); COUNT() GROUP BY Club HAVING COUNT()>1 (STEM 3, SPACE 2).

Part (b): MAX(Marks) and MIN(Marks) GROUP BY Gender — Male (91, 75), Female (70, 64).

The table School-data has a hyphen in its name, so it must be enclosed in backticks; otherwise SQL reads the hyphen as a minus operator. Parts (i) and (ii) are common to both options.

Part (a)

(i) Average marks by gender. GROUP BY Gender forms one bucket per gender and AVG(Marks) averages within each.

SELECT Gender, AVG(Marks) FROM `School-data` GROUP BY Gender;

Output:

Gender  AVG(Marks)
Male    84.0
Female  67.0

(ii) Minimum marks in Grade 10. Filter to Grade 10 with WHERE, then take MIN. No grouping is needed for a single value.

SELECT MIN(Marks) FROM `School-data` WHERE Grade = 10;

Grade-10 students score 75 (Alok) and 91 (Romil):

MIN(Marks)
75

(iii) Clubs having more than one student. Count per club with GROUP BY Club, then keep groups whose count exceeds 1 using HAVING (a WHERE cannot filter on an aggregate).

SELECT Club, COUNT(*) FROM `School-data` GROUP BY Club HAVING COUNT(*) > 1;

STEM has 3 (Sargam, Tanvi, Nomita), SPACE has 2 (Alok, Mohit), READER has 1:

Club   COUNT(*)
STEM   3
SPACE  2 …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.