Skip to content
Question
Q.

(a) Given the following tables:

Table: STUDENTS

S_IDNAMEAGECITY
1Rahul20Delhi
2Priya22Mumbai
3David21Delhi
4Neha23Bengaluru
5Khurshid22Delhi

Table: GRADES

S_IDSUBJECTGRADE
1MathA
2EnglishB
3MathC
4EnglishA
5MathB

Write SQL queries for the following:

  1. To display the number of students from each city.
  2. To find the average age of all students.
  3. To list the names of students and their grades. OR

(b) Consider the following tables:

Table 1: PRODUCTS This table stores the basic details of the products available in a shop.

PIDPNameCategory
201LaptopElectronics
202ChairFurniture
203DeskFurniture
204SmartphoneNULL
205TabletElectronics

Table 2: SALES This table records the number of units sold for each product.

SaleIDPIDUnitsSold
30120150
302202100
30320360
30420480
30520570

Write SQL queries for the following:

  1. To delete those records from table SALES whose UnitsSold is less than 80.
  2. To display names of all products whose category is not known.
  3. To display the product names along with their corresponding units sold.
CBSECBSE Class XII Board 2025Subjective· 3mImportance★★★★★
🔒 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): COUNT(*) GROUP BY CITY (Delhi 3, Mumbai 1, Bengaluru 1); AVG(AGE)=21.6; equi-join on S_ID for names+grades.

Part (b): DELETE FROM SALES WHERE UnitsSold<80 (removes 3 rows); WHERE Category IS NULL → Smartphone; equi-join on PID for names+units sold.

Part (a) — STUDENTS and GRADES

(i) Students per city. Group by CITY and count.

SELECT CITY, COUNT(*) FROM STUDENTS GROUP BY CITY;
CITY       COUNT(*)
Delhi      3
Mumbai     1
Bengaluru  1

(ii) Average age. A single aggregate over all rows.

SELECT AVG(AGE) FROM STUDENTS;

(20+22+21+23+22)=108, /5 = 21.6:

AVG(AGE)
21.6

(iii) Names and grades. The data lives in two tables linked by S_ID, so join them.

SELECT S.NAME, G.GRADE
FROM STUDENTS S, GRADES G
WHERE S.S_ID = G.S_ID;
NAME      GRADE
Rahul     A
Priya     B
David     C
Neha      A
Khurshid  B …

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.