0% found this document useful (0 votes)
6 views

Class 12 SQL Notes Detailed

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)
6 views

Class 12 SQL Notes Detailed

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
You are on page 1/ 4

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 students.name, marks.subject, marks.score

FROM students, marks

WHERE students.roll = marks.roll;

You might also like