Subject: Informatics Practices / Computer Science
Class: XII
Topic: Querying and SQL Functions
Time: 1 Hour
Marks: 30
Section A: Very Short Answer (1 mark each)
1. What is the purpose of the WHERE clause in SQL?
2. Write an SQL query to display the current date using a function.
3. Name any two aggregate functions in SQL.
4. Which SQL function returns the number of characters in a string?
Section B: Assertion and Reason (2 marks each)
Direction: For each question, choose the correct option:
• A. Both A and R are true, and R is the correct explanation of A.
• B. Both A and R are true, but R is not the correct explanation of A.
• C. A is true, but R is false.
• D. A is false, but R is true.
5.
Assertion (A): The AVG() function is used to find the maximum value in a column.
Reason (R): AVG() calculates the average of numeric values.
6.
Assertion (A): The GROUP BY clause is used with aggregate functions.
Reason (R): It groups rows that have the same values in specified columns.
Section C: Case-Based Questions (4 marks each)
Case 1:
Table: STUDENTS
ID Name Marks Grade
1 Riya 89 A
2 Kabir 76 B
3 Meera 65 C
4 Aarav 89 A
5 Ishita 92 A
7. Write SQL queries for the following:
o (i) Display the highest marks from the table.
o (ii) Count how many students got Grade 'A'.
o (iii) Show the average marks of all students.
Case 2:
Table: EMPLOYEES
EmpID Name Salary Department
101 Ravi 45000 Sales
102 Swati 52000 HR
103 Ankit 47000 IT
104 Priya 60000 Sales
105 Mehul 48000 IT
8. Write SQL queries for the following:
o (i) Display names of employees in the Sales department.
o (ii) Find the total salary paid by the company.
o (iii) Display department-wise average salary.
Section D: Short Answer (3 marks each)
9. Differentiate between single-row and aggregate functions with examples.
10. What is the role of GROUP BY and HAVING in SQL? Illustrate with a query.
Section E: Long Answer (5 marks)
11. Table: ORDERS
OrderID Customer Amount City
1 Ramesh 3000 Delhi
2 Alka 2500 Mumbai
3 John 4200 Delhi
4 Meena 1500 Kolkata
5 Suraj 2800 Mumbai
Write SQL queries to:
• (i) Find the total amount ordered from each city.
• (ii) Display only those cities where the total amount is more than 4000.
• (iii) Show all customer names in ascending order.
• (iv) Show the average order amount for Mumbai.
• (v) Count how many orders were placed from Delhi.
Instructions for Students:
• Write all queries clearly.
• Avoid using shorthand notations.
• Attempt all sections.