Chapter-4 Querying and SQL Functions — Online MCQ Test
INFORMATICS PRACTICES · Grade 12 · CBSE(NCERT)
Practice Chapter-4 Querying and SQL Functions with a free chapter-wise online MCQ test.
This chapter covers: SQL - single row functions - aggregate functions - SUM - AVG - COUNT - MAX - MIN - GROUP BY - HAVING - ORDER BY - table joins.
AI-generated questions from basic to board-exam level, with instant results and explanations.
Chapter-4 Querying and SQL Functions — Important Questions & Answers
Which SQL function is used to count the number of rows in a table?
- A. SUM()
- B. COUNT()
- C. AVG()
- D. MAX()
Answer: B. COUNT()
COUNT() is the aggregate function specifically designed to count the number of rows that match a specified condition in a table.
COUNT() is the aggregate function specifically designed to count the number of rows that match a specified condition in a table.
What does the AVG() function return?
- A. The total sum of all values
- B. The average or mean value of a numeric column
- C. The highest value in a column
- D. The lowest value in a column
Answer: B. The average or mean value of a numeric column
AVG() calculates and returns the average (mean) of all numeric values in a specified column.
AVG() calculates and returns the average (mean) of all numeric values in a specified column.
Which keyword is used to group rows that have the same values?
- A. ORDER BY
- B. GROUP BY
- C. FILTER
- D. PARTITION
Answer: B. GROUP BY
GROUP BY clause is used to group rows with identical values in specified columns, often used with aggregate functions.
GROUP BY clause is used to group rows with identical values in specified columns, often used with aggregate functions.
The MAX() function returns _______.
- A. The average of maximum values
- B. The highest value in a column
- C. The sum of all maximum values
- D. The count of maximum occurrences
Answer: B. The highest value in a column
MAX() function retrieves the single highest value present in the specified column.
MAX() function retrieves the single highest value present in the specified column.
Which of the following is NOT an aggregate function?
- A. SUM()
- B. COUNT()
- C. ROUND()
- D. AVG()
Answer: C. ROUND()
ROUND() is a scalar/single-row function that rounds numeric values, not an aggregate function that operates on multiple rows.
ROUND() is a scalar/single-row function that rounds numeric values, not an aggregate function that operates on multiple rows.
Consider a Students table with columns StudentID, Name, and Marks. What will SELECT COUNT(*) FROM Students return?
- A. The sum of all marks
- B. The total number of students in the table
- C. The number of unique student names
- D. The highest mark in the table
Answer: B. The total number of students in the table
COUNT(*) counts all rows in the table, returning the total number of student records.
COUNT(*) counts all rows in the table, returning the total number of student records.
What is a single-row function in SQL?
- A. A function that works on multiple rows at once
- B. A function that processes each row independently and returns one result per input row
- C. A function used only with GROUP BY
- D. A function that can only be used in WHERE clause
Answer: B. A function that processes each row independently and returns one result per input row
Single-row functions operate on each row individually and return one result for each input row, unlike aggregate functions that work on multiple rows.
Single-row functions operate on each row individually and return one result for each input row, unlike aggregate functions that work on multiple rows.
If you execute SELECT Department, SUM(Salary), COUNT(*) FROM Employees GROUP BY Department HAVING COUNT(*) > 5, what will be returned?
- A. All departments with their total salary and employee count
- B. Departments having more than 5 employees with their total salary and count
- C. Employees in departments with salary sum greater than 5
- D. All employees in departments sorted by salary
Answer: B. Departments having more than 5 employees with their total salary and count
The HAVING clause filters groups to show only departments with more than 5 employees, displaying their total salary and count.
The HAVING clause filters groups to show only departments with more than 5 employees, displaying their total salary and count.
Consider this scenario: You need to find the department with the highest total salary expense. Which query structure is most appropriate?
- A. SELECT Department FROM Employees ORDER BY Salary DESC LIMIT 1
- B. SELECT Department, SUM(Salary) FROM Employees GROUP BY Department ORDER BY SUM(Salary) DESC LIMIT 1
- C. SELECT Department, MAX(Salary) FROM Employees GROUP BY Department
- D. SELECT Department FROM Employees WHERE Salary = MAX(Salary)
Answer: B. SELECT Department, SUM(Salary) FROM Employees GROUP BY Department ORDER BY SUM(Salary) DESC LIMIT 1
This query correctly groups by department, sums all salaries per department, orders by total salary descending, and limits to the top result.
This query correctly groups by department, sums all salaries per department, orders by total salary descending, and limits to the top result.
If table Orders has columns OrderID and CustomerID, and table Customers has columns CustomerID and CustomerName, what does this query return? SELECT c.CustomerName, COUNT(o.OrderID) FROM Customers c LEFT JOIN Orders o ON c.CustomerID = o.CustomerID GROUP BY c.CustomerName HAVING COUNT(o.OrderID) = 0
- A. All customers with their order count
- B. Customers who have placed at least one order
- C. Customers who have never placed any order
- D. The total number of customers without orders
Answer: C. Customers who have never placed any order
LEFT JOIN keeps all customers; HAVING COUNT(o.OrderID) = 0 filters for customers with no matching orders, showing those who never ordered.
LEFT JOIN keeps all customers; HAVING COUNT(o.OrderID) = 0 filters for customers with no matching orders, showing those who never ordered.