0% found this document useful (0 votes)
22 views4 pages

Class 12 SQL Functions Overview

Notes

Uploaded by

25anonymous2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Class 12 SQL Functions Overview

Notes

Uploaded by

25anonymous2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Class 12 SQL Notes - Full Topic Guide

1. Math Functions

Math functions are used to perform mathematical operations in SQL.

1.1 POWER(x, y): Returns the result of x raised to the power y.

Example: POWER(2, 3) -> 8

1.2 ROUND(x, d): Rounds the number x to d decimal places. Useful for formatting results.

Example: ROUND(3.4567, 2) -> 3.46

1.3 MOD(x, y): Returns the remainder of x divided by y. Used for divisibility or alternating rows.

Example: MOD(10, 3) -> 1

2. Text/String Functions

Text functions are used to manipulate string values.

2.1 UPPER(text)/UCASE(text): Converts all characters to uppercase.

Example: UPPER('hello') -> 'HELLO'

2.2 LOWER(text)/LCASE(text): Converts all characters to lowercase.

Example: LOWER('WORLD') -> 'world'

2.3 MID(text, start, length) / SUBSTRING(text, start, length): Extracts part of a string from a given position.

Example: MID('COMPUTER', 2, 3) -> 'OMP'

2.4 LENGTH(text): Returns number of characters in the string including spaces.

Example: LENGTH('DATA') -> 4

2.5 LEFT(text, n): Returns first n characters from the left side.
Class 12 SQL Notes - Full Topic Guide

Example: LEFT('HELLO', 2) -> 'HE'

2.6 RIGHT(text, n): Returns last n characters from the right side.

Example: RIGHT('HELLO', 3) -> 'LLO'

2.7 INSTR(text, subtext): Returns position of subtext in the string.

Example: INSTR('HELLO', 'L') -> 3

2.8 LTRIM(), RTRIM(), TRIM(): Used to remove extra spaces.

LTRIM(' hello') -> 'hello'

RTRIM('hello ') -> 'hello'

TRIM(' hello ') -> 'hello'

3. Date Functions

Date functions are used to manipulate and extract information from date values.

3.1 NOW(): Returns current system date and time.

3.2 DATE(): Extracts only the date from a datetime value.

Example: DATE(NOW()) -> '2025-04-08'

3.3 MONTH(date): Returns the month as a number (1-12).

Example: MONTH('2025-04-08') -> 4

3.4 MONTHNAME(date): Returns the full name of the month.

Example: MONTHNAME('2025-04-08') -> 'April'

3.5 YEAR(date): Returns the year part of the date.

Example: YEAR('2025-04-08') -> 2025


Class 12 SQL Notes - Full Topic Guide

3.6 DAY(date): Returns the day of the month.

Example: DAY('2025-04-08') -> 8

3.7 DAYNAME(date): Returns the day name.

Example: DAYNAME('2025-04-08') -> 'Tuesday'

4. Aggregate Functions

Aggregate functions are used to calculate a single value from a group of rows.

MAX(column): Returns highest value from a column.

Example: MAX(marks)

MIN(column): Returns lowest value from a column.

Example: MIN(marks)

AVG(column): Calculates average value of a column.

Example: AVG(marks)

SUM(column): Returns total sum of values.

Example: SUM(marks)

COUNT(column): Counts non-null values.

Example: COUNT(name)

COUNT(*): Counts all rows including nulls.

Example: COUNT(*)

5. GROUP BY, HAVING, ORDER BY


Class 12 SQL Notes - Full Topic Guide

These clauses help to group, filter, and sort data.

GROUP BY: Groups rows based on a column value.

Example:

SELECT city, COUNT(*) FROM students GROUP BY city;

HAVING: Filters grouped results, used after GROUP BY.

Example:

SELECT city, COUNT(*) FROM students GROUP BY city HAVING COUNT(*) > 2;

ORDER BY: Sorts records in ascending (ASC) or descending (DESC) order.

Example:

SELECT name, marks FROM students ORDER BY marks DESC;

6. Equi-Join (Joining Two Tables)

Equi-Join is used to retrieve data from two or more tables using a common column.

It uses the equality operator (=) to match rows.

Example:

Table1: students(roll, name)

Table2: marks(roll, subject, score)

Query:

SELECT [Link], [Link], [Link]

FROM students, marks

WHERE [Link] = [Link];

Common questions

Powered by AI

Mathematical functions like POWER, ROUND, and MOD are crucial in SQL for performing numerical operations. POWER(x, y) computes x raised to the power y, useful in calculations involving exponential growth. ROUND(x, d) rounds numbers to a specified number of decimal places, essential for formatting numeric output. MOD(x, y) returns the remainder of x divided by y, often used in determining divisibility or implementing alternating logic in queries .

Aggregate functions calculate a single result from a set of input values. MAX() returns the highest value in a column, which is useful for identifying upper limits or extremes in data sets. COUNT counts the number of non-null values or all rows, helping in determining the size of datasets or detecting null distribution. They are used in summarizing data, such as finding maximum sales figures or counting attendees in an event database .

The COUNT function determines the number of rows that share specific characteristics, either all rows (COUNT(*)) or those with non-null entries in a specified column (COUNT(column)). This is instrumental for data summarization and integrity checks, such as counting total entries in a dataset, calculating the extent of non-null entries for data completeness, or in combination with GROUP BY to get category-wise totals, like number of students per class .

GROUP BY organizes rows into groups based on column values, which can then be filtered using HAVING to impose conditions on group results, such as only showing groups with a count greater than a threshold. ORDER BY then sorts the resulting dataset, either in ascending or descending order, to enhance readability or align with business needs. This combination allows for comprehensive and refined query outputs like ranked sales by region or high-performing product categories .

ORDER BY sorts the rows returned by an SQL query based on one or more specified columns, either in ascending or descending order. This is essential for organizing query outputs for better readability or logical order expected by end-users. For example, when querying a student database, using ORDER BY marks DESC will list students in order of their scores, pinpointing top performers immediately .

SQL date functions are highly effective in managing complex time-based datasets by providing intuitive methods to extract and manipulate date parts, simplifying temporal queries. Functions such as YEAR, MONTH, and DAY facilitate precise filtering and grouping operations, which are crucial in time series analysis and monthly or yearly reporting. NOW's ability to provide exact current timestamps aids in real-time applications and logging. Despite their effectiveness, dependence on SQL date functions may require vigilant considerations of time zone issues and daylight saving variations, which can complicate queries, demanding thorough understanding and careful application .

SQL string functions offer strategic advantages in data manipulation and query formulation by enabling efficient text transformation and analysis. Functions like UPPER and LOWER standardize text casing for uniform data comparison, enhancing consistency in results. MID and SUBSTRING allow extraction of precise portions of strings, vital for data parsing and extraction tasks. These functions, collectively, empower developers to manipulate and tailor string data without the need for complex procedural code, optimizing database performance and reducing the need for post-processing .

Date functions facilitate handling and querying date and time information. NOW() returns the current date and time, useful for capturing timestamps in logs or transactions. DAYNAME extracts the weekday from a date, aiding in generating reports segmented by days of the week. YEAR extracts the year component, useful when performing year-on-year comparisons or filtering records by specific years .

An Equi-Join retrieves data by matching rows from two or more tables based on common column values, utilizing the equality operator. It is foundational for accessing relational datasets to bring together complete records. For instance, by joining a 'students' table with a 'marks' table on their common 'roll' column, one can access comprehensive data on student names alongside their scores in various subjects, which is crucial in generating reports or compiling datasets for deeper analysis .

Text functions are used to manipulate and format string data. UPPER converts text to uppercase, beneficial in ensuring uniformity in case-insensitive comparisons or standardizing inputs. MID extracts a substring from a string, useful for isolating specific data segments, such as extracting area codes from phone numbers. INSTR finds the position of a substring within a string, which can be employed in validations or parsing tasks to locate specific information within larger text fields .

You might also like