Curriculum
Course: Grade XII Informatics Practices
Login
Text lesson

Ch-1 Querying and SQL Functions

School Revise · Class 12 Information Practices · Chapter 1

Querying and SQL Functions

Code 065, Class 12. SQL functions summarise and shape the data in a table. Here we use aggregate, text, number and date functions, and group rows with GROUP BY.

5

aggregate functions

GROUP BY

summarise groups

What this chapter is about

Functions in SQL work on the data in a table. Some summarise many rows into one value, and others change text, numbers or dates. GROUP BY makes summaries per group.

1. Aggregate functions

These summarise a column: COUNT counts rows, SUM adds, AVG averages, and MAX and MIN find the largest and smallest.

SELECT AVG(salary) FROM EMP; (shows the average of the salary column)

2. Text, number and date functions

Text: UCASE and LCASE change case, LENGTH counts characters, MID takes part of a string. Number: ROUND, POWER, MOD. Date: NOW, YEAR, MONTH, DAY.

3. GROUP BY and HAVING

GROUP BY makes one summary row per group, for example the average salary in each department. HAVING filters those groups, like a WHERE for groups.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Count the rows in a table.

SOLUTION

SELECT COUNT(*) FROM EMP;

OUTPUT

the number of rows
Problem 2. Find the total of all salaries.

SOLUTION

SELECT SUM(salary) FROM EMP;

OUTPUT

the sum of the salary column
Problem 3. Find the average salary.

SOLUTION

SELECT AVG(salary) FROM EMP;

OUTPUT

the average of the salary column
Problem 4. Find the highest salary.

SOLUTION

SELECT MAX(salary) FROM EMP;

OUTPUT

the largest salary
Problem 5. Count employees in each department.

SOLUTION

SELECT dept, COUNT(*) FROM EMP GROUP BY dept;

OUTPUT

one row per department with its count
Problem 6. Show names in capital letters.

SOLUTION

SELECT UCASE(name) FROM EMP;

OUTPUT

the name column in uppercase
Problem 7. Show the length of each name.

SOLUTION

SELECT name, LENGTH(name) FROM EMP;

OUTPUT

each name with its number of characters
Problem 8. Round the salary to a whole number.

SOLUTION

SELECT ROUND(salary, 0) FROM EMP;

OUTPUT

the salary rounded to no decimals
Problem 9. Show the current year.

SOLUTION

SELECT YEAR(NOW());

OUTPUT

the current year
Problem 10. Show departments whose average salary is above 50000.

SOLUTION

SELECT dept, AVG(salary) FROM EMP GROUP BY dept HAVING AVG(salary) > 50000;

OUTPUT

groups with average salary above 50000

Practice set A, multiple choice

1. Which function counts rows?

COUNT.

2. Which clause makes one summary per group?

GROUP BY.

3. Which function changes text to capitals?

UCASE (or UPPER).

4. Which clause filters groups?

HAVING.

Quick summary

SQL functions work on table data. Aggregate functions COUNT, SUM, AVG, MAX and MIN summarise a column. Text functions (UCASE, LCASE, LENGTH, MID), number functions (ROUND, POWER, MOD) and date functions (NOW, YEAR, MONTH) shape single values. GROUP BY makes one summary per group, and HAVING filters those groups.

Open the Virtual Lab

These free Class 12 Informatics Practices notes explain SQL functions, aggregate functions COUNT SUM AVG MAX and MIN, text number and date functions, and GROUP BY with HAVING with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Informatics Practices syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories