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

Class 12 Notes

The document provides an overview of MySQL functions categorized into four types: String Functions, Numerical Functions, Date & Time Functions, and Aggregate Functions. It explains the differences between Single Row Functions, which process individual rows, and Multiple Row Functions, which operate on groups of rows. Each function type is illustrated with examples and their respective SQL queries to demonstrate usage.

Uploaded by

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

Class 12 Notes

The document provides an overview of MySQL functions categorized into four types: String Functions, Numerical Functions, Date & Time Functions, and Aggregate Functions. It explains the differences between Single Row Functions, which process individual rows, and Multiple Row Functions, which operate on groups of rows. Each function type is illustrated with examples and their respective SQL queries to demonstrate usage.

Uploaded by

jangirtiksha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Class – XII (2025 – 26)

My SQL
Ch – 1 (SQL Queries using Functions)

MySQL Functions – In MySQL we have four types of functions.


1. String Function (Single Row Function)
2. Numerical Function (Single Row Function)
3. Date & time Function (Single Row Function)
4. Aggregate Function (Multiple Row Function)

Single Row Function Vs Multiple Row Function


Single Row Function - Single Row Function process individual rows in a table
and return a single value for each row.
For example – ucase(), left(), mod(), date()

Multiple Row Function – Multiple row function also known as aggregate


function operate on a group of rows or all rows of a table and return a single
result summarizing those rows.
For example – sum(), Min(), Max()

1. String Function
These are the Single Row Functions. These Functions only works with string
columns.
(i)Upper() / Ucase()-This string function use to convert all the alphabets in
capital letters.
Example - Select ucase(“Informatics Practices”)
Result - INFORMATICS PRACTICES
(ii)lower() / Lcase()-This string function use to convert all the alphabets in small
letters.
Example - Select Lcase(“Informatics Practices”)
Result - informatics practices

(iii) length() - This string function use to display the length of a string.
Example - Select length(“Informatics Practices”)
Result - 21

(iv) left()- This string function use to display the substring from left side of a
string on given length.
Example - Select left(“Informatics Practices”,6)
Result - Inform

(v) right()- This string function use to display the substring from right side of a
string on given length.
Example - Select right(“Informatics Practices”,3)
Result - ces

(vi) mid()/substr()/substring()-This string function use to display the substring


from anywhere position of a string given by user on given length.
Note-if user not enter the length it will take all characters till end of the string.
Example – Select mid(“Informatics Practices”,6,6)
Result - matics
(vii) ltrim()- this string function is used to remove space from left hand side of
string(Leading space).
Example - Select ltrim(“ Informatics Practices ”)
Result - “Informatics Practices ”

(viii) rtrim()- this string function is used to remove space from right hand side of
string(trailing space).
Example - Select rtrim(“ Informatics Practices ”)
Result - “ Informatics Practices”

(ix) trim()- this string function is used to remove space from both sides of string
(Leading & trailing space both ).
Example - Select trim(“ Informatics Practices ”)
Result - “Informatics Practices”

(x) instr()- This string function use to display the position of substring from a
string on given character(s).
Example – Select instr(“Informatics Practices”, “for”)
Result - 3

2. Numerical Function
These are the Single Row Functions. These functions works on integer or float
datatypes.
(i) Pow()/Power()- this function is used to display any power of any no.
Example - Select power(10,3)
Result - 1000
(ii) sqrt() – this Function is used to calculate square root of a number.
Example - Select sqrt(121)
Result - 11

(iii) mod()-This function is used to find the remainder for a no.


Example - Select mod(10,3)
Result - 1

(iv) round()-This function is used to round figure the digit to its near by digit of
given size.
Example - Select round(76892.52865,3)
Result - 76892.529

Example - Select round(76892.52865,-4)


Result - 80000

Example - Select round(76892.52865,2)


Result - 76892.52

(v) truncate-this function is used to only remove the digit on given size.
Example - Select truncate (76892.52865,3)
Result - 76892.528

Example - Select truncate (76892.52865,-4)


Result - 70000
Example - Select truncate (76892.52865,2)
Result - 76892.52

3. Date & Time Function


These are the Single Row Functions. These functions works on date and time
datatype.
(i) Now() / sysdate()-It will return system current date and time
Example - Select now()
Result - 25-04-2025 11:42:47

(ii) curdate() - It will return system current date only.


Example - Select curdate()
Result - 25-04-2025

(iii) curtime() - It will return system current time only.


Example – Select curtime()
Result - 11:42:47

(iv) date()- It will return date only from date time format of given data.
Example - Select date(‘2025-04-20 08:50:52’)
Result - 2025-04-20

(v) time()- It will return time only from date time format of given data.
Example - Select time(‘2025-04-20 08:50:52’)
Result - 08:50:52
(vi) year ()- It will return year only from date time format of given data.
Example - Select year(‘2025-04-20 08:50:52’)
Result - 2025

(vii) month()- It will return month only from date time format of given data.
Example - Select month(‘2025-04-20 08:50:52’)
Result - 04

(viii) day()- It will return day only from date time format of given data.
Example - Select day(‘2025-04-20 08:50:52’)
Result - 20

(ix) hour()- It will return hour only from date time format of given data.
Example - Select hour(‘2025-04-20 08:50:52’)
Result - 08

(x) minute()- It will return minute only from date time format of given data.
Example - Select minute(‘2025-04-20 08:50:52’)
Result - 50

(xi) second()- It will return second only from date time format of given data.
Example - Select second(‘2025-04-20 08:50:52’)
Result - 52
(xii) monthname() - It will return month name only from date time format of
given data.
Example - Select monthname(‘2025-04-20’)
Result - April

(xiii) dayname() - It will return day name like Sunday Monday only from date
time format of given data.
Example - Select dayname(‘2025-04-20‘)
Result - Sunday

(xiv) dayofweek() - It will return day number from weekdays like 1-Sunday, 2-
Monday up so on.
Example - Select dayofweek(‘2025-04-20‘)
Result - 1

(xiv) dayofmonth() - It will return day number from month


Example - Select dayofmonth(‘2025-04-20‘)
Result - 20

(xiv) dayofyear() - It will return day number from a year(365) or leap year(366)
Example - Select dayofyear(‘2025-04-20‘)
Result - 110
4. Aggregate Function
These are the Multiple Row Functions. These function works along with MySQL
tables. We can use Group by Clause and Having Clause with these functions
Table: Student
RollNo Name DOB Class Fees Sports
1 Aman Sharma 2008-11-12 11 10000 Basketball
2 Rohit Kumar 2009-01-01 11 20000 Football
3 Ravi Jain 2008-04-05 12 10000 Basketball
4 Puneet Gupte 2009-03-11 11 15000 Basketball
5 Abhay Sharma 2009-12-25 11 NULL Tennis
6 Yash Godha 2008-07-01 12 10000 Cricket
7 Mohit Sharma 2008-09-09 11 15000 Cricket
8 Pawan Jain 2007-05-12 12 10000 Tennis
9 Pulkit Kumar 2009-10-21 10 15000 Football
10 Suyash Mehra 2008-07-07 11 20000 Cricket

(i) Sum() – This Function given the sum of all values from the table column.
Example – Select Sum(Fees) from Student;
Result – 125000

(ii) Min() – This Function given the Minimum values from the table column.
Example – Select Min(Class) from Student;
Result – 10

Example – Select Min(DOB) from Student;


Result – 2007-05-12

Example – Select Min(Name) from Student;


Result – Abhay Sharma
(iii) Max() – This Function given the Maximum values from the table column.
Example – Select Max(Fees) from Student;
Result – 20000

Example – Select Max(DOB) from Student;


Result – 2009-12-25

Example – Select Max(Sports) from Student;


Result – Tennis

(iv) Avg() – This Function given the average values from the table column. It not
count the null value in it.
Example – Select Avg(Fees) from Student;
(125000/9)
Result – 13888.88

(v) Count(*) or Count(column name) –


Count(*) function always count the total no of rows from the table. If there is
any null values in these rows it is also counted.
Count(Column name) function count the total no of data in given column.
If there are some null value in the column it will not be counted.
Example – Select count(*) from Student;
Result – 10

Example – Select count(fees) from Student;


Result – 09
Example – Select count(Sports) from Student;
Result – 10

GROUP by Clause
This Clause works with only aggregate function of MySQL. This function works
with group of the data.
Example – Select Sports, count(*) from Student Group by sports;
Result –
Sports Count(*)
Basketball 3
Football 2
Tennis 2
Cricket 3

You might also like