AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Informatics Practices

Querying and SQL Functions

Standard difficulty · 20 questions · 40 marks · Time: 39 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
A single row function in SQL:
  1. works only on numbers
  2. can be used only after GROUP BY
  3. gives one result for the whole table
  4. gives one result for each row it is applied to
2.
What does this query return?
SELECT ROUND(926.716, 2);
  1. 926.73
  2. 927
  3. 926.72
  4. 926.716
3.
What does this query return?
SELECT MID('Spreadsheet', 2, 3);
  1. pre
  2. rea
  3. Spr
  4. pr
4.
What does this query return?
SELECT DAYNAME('2025-07-09');
  1. Thursday
  2. Saturday
  3. Wednesday
  4. Sunday
5.
Table STUDENT
RollNo | Name | City | Marks
1 | Gita | Surat | 85
2 | Vikram | Mysuru | 68
3 | Asha | Delhi | 89
4 | Rohan | Surat | NULL
5 | Zoya | Mysuru | NULL
6 | Arjun | Surat | 94
What does this query return?
SELECT COUNT(DISTINCT City) FROM STUDENT;
  1. 6
  2. 5
  3. 4
  4. 3
6.
Table STUDENT
RollNo | Name | City | Marks
1 | Zoya | Shimla | 86
2 | Kabir | Shimla | 74
3 | Karan | Kochi | 99
4 | Manav | Delhi | 96
5 | Tara | Delhi | 90
How many rows does this query return?
SELECT City, COUNT(*) FROM STUDENT GROUP BY City HAVING COUNT(*) > 1;
  1. 1
  2. 2
  3. 3
  4. 5
7.
Table A has 2 columns and 3 rows; table B has 4 columns and 6 rows. What are the degree and cardinality of their Cartesian product A × B?
  1. degree 4, cardinality 18
  2. degree 8, cardinality 18
  3. degree 6, cardinality 18
  4. degree 6, cardinality 21
8.
Which would you use in a query to get the number of rows in a table?
  1. NOW()
  2. COUNT(*)
  3. AVG()
  4. MAX()
Section B — Short answer8 × 2 = 16 marks
9.
Name the three categories of single row functions in MySQL and give one example of each.
10.
Write the output of:
SELECT ROUND(861.398, 1);
11.
The text below has 4 spaces before the word and 3 after it. Write the output of:
SELECT LENGTH(RTRIM('    Monitor   '));
12.
Write the output of:
SELECT LOWER(RIGHT('Software', 2));
13.
Write the output of:
SELECT MONTH('2026-08-12');
14.
Table ITEM
ICode | IName | Store | Price
I01 | Crayons | East | 405
I02 | Eraser | West | 35
I03 | Glue | East | 490
I04 | Pen | North | 355
I05 | Notebook | North | 180
Write the output of:
SELECT MIN(Price) FROM ITEM WHERE Store = 'North';
15.
Table STUDENT
RollNo | Name | City | Marks
1 | Sana | Jaipur | 99
2 | Gita | Shimla | 87
3 | Manav | Shimla | 84
4 | Tara | Shimla | 54
5 | Arjun | Indore | 60
Write the output of:
SELECT City, COUNT(*) FROM STUDENT GROUP BY City ORDER BY City;
16.
Table STUDENT
RollNo | Name | City | Marks
1 | Diya | Surat | 98
2 | Meena | Pune | 94
3 | Ravi | Pune | 56
4 | Rohan | Shimla | 54
5 | Zoya | Surat | 61
Which values does this query show, in order? Write them separated by commas.
SELECT Name FROM STUDENT WHERE Marks > 56 ORDER BY Marks DESC;
Section C — Word problems4 × 4 = 16 marks
17.
Explain GROUP BY and HAVING with a suitable example query.
18.
Table ITEM
ICode | IName | Store | Price
I01 | Ruler | East | 90
I02 | Sharpener | South | 420
I03 | Notebook | North | 345
I04 | Scissors | East | 145
I05 | Crayons | South | 340
I06 | Pen | South | 95
I07 | Folder | North | 110
Write the output of each query.
(a) SELECT COUNT(*) FROM ITEM WHERE Store = 'South';
(b) SELECT SUM(Price) FROM ITEM WHERE Price >= 110;
(c) SELECT MAX(Price) - MIN(Price) FROM ITEM;
19.
Table EMPLOYEE
EmpId | EName | DeptId
101 | Imran | D4
102 | Rohan | D4
103 | Farhan | D3
104 | Pooja | D4
105 | Isha | D2
Table DEPT
DeptId | DName
D1 | Support
D2 | Training
D3 | Sales
D4 | Accounts
(a) Write the output of:
SELECT EName, DName FROM EMPLOYEE, DEPT WHERE EMPLOYEE.DeptId = DEPT.DeptId ORDER BY EName;
(b) How many rows would SELECT * FROM EMPLOYEE, DEPT; return?
20.
Table ITEM
ICode | IName | Store | Price | StockDate
I01 | Glue | North | 25 | 2025-02-20
I02 | Diary | North | 235 | 2026-09-25
I03 | Notebook | North | 110 | 2025-10-10
I04 | Scissors | North | 365 | 2026-11-18
I05 | Stapler | South | 445 | 2025-02-26
I06 | Crayons | Central | 375 | 2026-02-14
Write SQL queries to:
(a) display the IName of the items whose Store is North, in alphabetical order;
(b) display each Store with the highest Price in it;
(c) display the IName and the year of StockDate of the items whose StockDate falls in February.
AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Informatics Practices

Answer key

Querying and SQL Functions · AW-12IP-SQF-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) gives one result for each row it is applied to—
2(c) 926.72ROUND keeps 2 decimal places, rounding a 5 or more up
3(a) pre3 letters from position 2: pre
4(c) Wednesday2025-07-09 falls on a Wednesday
5(d) 3COUNT(DISTINCT …) counts each different value once
6(b) 25 rows make 3 groups; HAVING keeps the groups with more than 1
7(c) degree 6, cardinality 18columns add: 2 + 4; rows multiply: 3 × 6
8(b) COUNT(*)—
9Math (numeric) functions, e.g. ROUND(); text (string) functions, e.g. LENGTH(); date functions, e.g. MONTH().—
10861.4round 861.398 to 1 decimal place
1111RTRIM removes the trailing spaces; 7 letters + 4
12reRIGHT gives re; LOWER makes it small letters
1382026-08-12: year 2026, month 8, day 12
14180Store = 'North': 355, 180
15City | COUNT(*)
Indore | 1
Jaipur | 1
Shimla | 3
one row for each group, in alphabetical order of the group
16Diya, Meena, ZoyaMarks > 56, arranged highest first
17GROUP BY collects rows with the same value of a column into groups; an aggregate function then gives one value per group. HAVING keeps only the groups that satisfy a condition. Example: SELECT City, COUNT(*) FROM STUDENT GROUP BY City HAVING COUNT(*) > 2; lists each city with more than two students and the number of students.definition of each (2); a correct query (2)
18(a) 3; (b) 1360; (c) 330(b) adds the Price values of 110 or more; (c) is 420 − 90
19(a) EName | DName
Farhan | Sales
Imran | Accounts
Isha | Training
Pooja | Accounts
Rohan | Accounts
(b) 20
(a) an equi-join keeps only the pairs with matching DeptId, here sorted by EName; (b) the Cartesian product has 5 × 4 rows
20(a) SELECT IName FROM ITEM WHERE Store = 'North' ORDER BY IName;
(b) SELECT Store, MAX(Price) FROM ITEM GROUP BY Store;
(c) SELECT IName, YEAR(StockDate) FROM ITEM WHERE MONTH(StockDate) = 2;
any equivalent query is correct (for example, ORDER BY … ASC in (a))