SQL: Aggregates, Grouping and Joins: Class 12 PYQs 2024–2026 with solutions
All 11 CBSE board questions asked from SQL: Aggregates, Grouping and Joins in 3 board papers, with the year, set and marks of each. 7 are solved free below. The Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE) has every solution, all chapters and 3 full board papers.
SQL: Aggregates, Grouping and Joins: board weightage
Board weightage 2024–2026
| Year | 2024 | 2025 | 2026 |
|---|---|---|---|
| Questions | 4 | 4 | 3 |
| Marks | 9 | 10 | 9 |
Most asked topics
11 questions from 3 papers. Repeated questions are shown once with every year they were asked.
1 mark: MCQ and Assertion–Reason
Which aggregate function returns the smallest value from a column? (A) MIN() (B) MAX() (C) SMALL() (D) LOWER()
Solution
(A) MIN().
Which aggregate function displays the number of values in a column ignoring NULL values? (A) len() (B) count() (C) number() (D) num()
Solution
(B) count(), i.e. COUNT(column).
True or False: If table A has 6 rows and 3 columns and table B has 5 rows and 2 columns, the Cartesian product of A and B will have 30 rows and 5 columns.
Solution
True: rows 6 × 5 = 30; columns 3 + 2 = 5.
The aggregate function which will display the cardinality of a table is ____. (a) sum() (b) count(*) (c) avg() (d) sum(*)
(A)(i) Define Cartesian Product with respect to RDBMS.
3 marks: short answer
Table ORDERS: (1001 RICE 23 120 2023-09-10), (1002 PULSES 13 120 2023-10-18), (1003 RICE 25 110 2023-11-17), (1004 WHEAT 28 65 2023-12-25), (1005 PULSES 16 110 2024-01-15), (1006 WHEAT 27 55 2024-04-15), (1007 WHEAT 25 60 2024-04-30) [ORDNO ITEM QTY RATE ORDATE]. Output: (i) SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM; (ii) SELECT ITEM, QTY FROM ORDERS WHERE ORDATE BETWEEN '2023-11-01' AND '2023-12-31'; (iii) SELECT ORDNO, ORDATE FROM ORDERS WHERE ITEM='WHEAT' AND RATE>=60;
Solution
(i) RICE 23 + 25; PULSES 13 + 16; WHEAT 28 + 27 + 25.
RICE 48
PULSES 29
WHEAT 80
(ii) Orders in Nov–Dec 2023: 1003, 1004.
RICE 25
WHEAT 28
(iii) WHEAT rows 1004 (65), 1006 (55 ✗), 1007 (60).
1004 2023-12-25
1007 2024-04-30
4 marks: SQL / case-based
Table STOCK (13.1). (a) Write queries: (i) Type and maximum Price for each Type; (ii) increase Price by 0.5 where Type is 'F'; (iii) total value of stock (total of Qty × Price); (iv) details of records where Code starts with 'A'.
OR (b) OR, outputs: (i) SELECT Volume, Qty, Price FROM STOCK WHERE Type IN ('F','D'); (ii) SELECT Code, Qty FROM STOCK WHERE Price BETWEEN 30 AND 50; (iii) SELECT DISTINCT Type FROM STOCK; (iv) SELECT Volume, count(*) FROM STOCK GROUP BY Volume;
Solution
(i) SELECT Type, MAX(Price) FROM STOCK GROUP BY Type;
(ii) UPDATE STOCK SET Price = Price + 0.5 WHERE Type = 'F';
(iii) SELECT SUM(Qty * Price) FROM STOCK; -- 41665.00
(iv) SELECT * FROM STOCK WHERE Code LIKE 'A%'; -- AF0.5, AT1.0
OR
(i) 0.5 300 38.00(ii) BETWEEN is inclusive, so PT0.5 at exactly 30.00 is included.
0.5 250 36.50
1.0 50 52.00
(ii) AF0.5 300
MF0.5 250
PT0.5 78
(iii) F
T
D
(iv) 0.5 3
1.0 3
CUSTOMERS and LOANS (13.4). Write queries for: (i) number of LOANS records with RoI above 7.0; (ii) names of customers whose L_Amt is above 1000000; (iii) C_ID, C_Name and Terms of records with L_Date after 31 December 2024; (iv)(a) details of all loans in descending order of RoI, OR (b) C_ID and average term for each C_ID from LOANS.
Solution
(i) SELECT COUNT(*) FROM LOANS WHERE RoI > 7.0; -- 3(iii) gives 00003 David Xavier 60; 00001 Raj Malhotra 48; 00003 David Xavier 36; 00004 Damini Iyer 60. Write C.C_ID (not just C_ID) in a join, or MySQL reports an ambiguous column.
(ii) SELECT C_Name FROM CUSTOMERS, LOANS
WHERE CUSTOMERS.C_ID = LOANS.C_ID AND L_Amt > 1000000; -- Abdul
(iii) SELECT C.C_ID, C_Name, Terms FROM CUSTOMERS C, LOANS L
WHERE C.C_ID = L.C_ID AND L_Date > '2024-12-31';
(iv)(a) SELECT * FROM LOANS ORDER BY RoI DESC;
(iv)(b) SELECT C_ID, AVG(Terms) FROM LOANS GROUP BY C_ID;
(b) Table WORKER (Chapter 12): outputs of (i) SELECT WNAME, WAGE*HOURS FROM WORKER WHERE SITEID = 103; (ii) SELECT COUNT(DISTINCT TYPE) FROM WORKER; (iii) SELECT MAX(WAGE), MIN(WAGE), TYPE FROM WORKER GROUP BY TYPE; (iv) SELECT WNAME, SITEID FROM WORKER WHERE TYPE="Unskilled" ORDER BY HOURS;
Solution
(i) Site 103: Ahmed J 1500 × 200, Anju S 1200 × 130.
Ahmed J 300000
Anju S 156000
(ii) Types: Unskilled, Skilled, Semiskilled.
3
(iii)
1500 780 Unskilled
1200 520 Skilled
560 560 Semiskilled
(iv) Unskilled: Jacob B (95 h), Ahmed J (200 h).
Jacob B 101
Ahmed J 103
Creative Art Gallery: Articles(Code, A_Code, Article, DOC, Price) and Artists(A_Code, Name, Phone, Email, DOB). Write queries: (i) all records of Articles in descending order of price; (ii) Articles created in the year 2020; (iii) structure of Artists; (iv)(a) names of all Artists whose Article is Painting through Equi Join, OR (b) through Natural Join.
Tables Admin(S_id, S_name, Address, S_type) and Transport(S_id, Bus_no, Stop_name). Write SQL: (i) student name and stop name from both tables; (ii) number of students whose S_type is not known; (iii) all details of students whose name starts with 'V'; (iv) student id and address in alphabetical order of student name.
Get every solution for all chapters
- Every board question of every chapter, each fully solved the way the board gives marks
- 3 complete board papers, each followed by its solutions
- Weightage and most-asked topics for every chapter
- Instant PDF download, colour and black & white print copies
Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →
What you get in the pack
- CBSE Class 12 Computer Science board papers 2024 to 2026 (3 full board papers)
- All 14 chapters and 3 board papers complete
- Part A: all 14 chapters, questions sorted chapter-wise and by marks
- Year-wise weightage table and most-asked topics for every chapter
- Part B: each full board paper followed by its complete solutions
- Full programs; every output traced and verified by running the code
- Only the current syllabus in Part A
All chapters in this pack
- PYQ Ch 1 Python Revision Tour
- PYQ Ch 2 Functions
- PYQ Ch 3 Exception Handling
- PYQ Ch 4 Text Files
- PYQ Ch 5 Binary Files
- PYQ Ch 6 CSV Files
- PYQ Ch 7 Stack
- PYQ Ch 8 Computer Networks I: Evolution and Data Communication
- PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
- PYQ Ch 10 Network Protocols and Web Services
- PYQ Ch 11 Database Concepts
- PYQ Ch 12 SQL: DDL, DML and Queries
- PYQ Ch 13 SQL: Aggregates, Grouping and Joins
- PYQ Ch 14 Interface of Python with MySQL
- Board Paper 2026 Set 91 with Solutions
- Board Paper 2025 Set 91 with Solutions
- Board Paper 2024 Set 91 with Solutions
