0% found this document useful (0 votes)
1 views3 pages

Functions

MySQL offers various built-in functions categorized into Aggregate, String, Numeric, Date and Time, Control Flow, and Other Utility Functions. Each category contains specific functions that perform operations on data, such as calculating sums, manipulating strings, and handling date/time values. Examples of these functions include SUM(), CONCAT(), ROUND(), NOW(), and IF().

Uploaded by

sathiya
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)
1 views3 pages

Functions

MySQL offers various built-in functions categorized into Aggregate, String, Numeric, Date and Time, Control Flow, and Other Utility Functions. Each category contains specific functions that perform operations on data, such as calculating sums, manipulating strings, and handling date/time values. Examples of these functions include SUM(), CONCAT(), ROUND(), NOW(), and IF().

Uploaded by

sathiya
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/ 3

MySQL provides built-in functions to perform operations on data.

They can be categorised


into:

1. Aggregate Functions
2. String Functions
3. Numeric Functions
4. Date and Time Functions
5. Control Flow Functions
6. Other Utility Functions

🔷 1. Aggregate Functions

These operate on sets of rows and return a single value.

Function Purpose Example


SUM() Adds up values SELECT SUM(salary) FROM Employee;
AVG() Calculates average SELECT AVG(marks) FROM Student;
COUNT() Counts rows SELECT COUNT(*) FROM Orders;
MAX() Finds maximum value SELECT MAX(price) FROM Product;
MIN() Finds minimum value SELECT MIN(age) FROM Person;

🔷 2. String Functions

Operate on character data types.

Function Purpose Example


SELECT CONCAT(first_name, ' ', last_name) FROM
CONCAT() Combine strings Employee;
LENGTH() String length SELECT LENGTH(name) FROM Student;

LOWER()
Converts to SELECT LOWER(city) FROM Address;
lowercase
UPPER()
Converts to SELECT UPPER(department) FROM Dept;
uppercase
SUBSTRING()
Extract part of SELECT SUBSTRING(name,1,3) FROM Student;
string
SELECT
REPLACE() Replace substring REPLACE(email,'@gmail.com','@outlook.com') FROM
Users;
Remove
TRIM() leading/trailing SELECT TRIM(name) FROM Student;
spaces

🔷 3. Numeric Functions

Perform operations on numeric data.


Function Purpose Example
ROUND() Rounds number SELECT ROUND(price,2) FROM Product;
CEIL() Smallest integer ≥ value SELECT CEIL(4.2); →5
FLOOR() Largest integer ≤ value SELECT FLOOR(4.8); → 4
ABS() Absolute value SELECT ABS(-25); → 25
MOD() Modulo division SELECT MOD(10,3); → 1
POWER() Power of number SELECT POWER(2,3); → 8

🔷 4. Date and Time Functions

Operate on date/time data types.

Function Purpose Example


NOW()
Current date and SELECT NOW();
time
CURDATE() Current date SELECT CURDATE();
CURTIME() Current time SELECT CURTIME();
DATE() Extract date part SELECT DATE(NOW());
DAY(), MONTH(), Extract day, month, SELECT YEAR(dob) FROM Student;
YEAR() year
DATEDIFF()
Difference between SELECT DATEDIFF('2025-12-31','2025-01-
dates 01'); → 364

🔷 5. Control Flow Functions

Provide conditional logic.

Function Purpose Example


IF() If-else logic SELECT IF(marks>=50,'Pass','Fail') FROM Student;
CASE Multiple conditions
sql
CopyEdit
SELECT name,
CASE
WHEN marks >= 90 THEN 'A'
WHEN marks >= 80 THEN 'B'
ELSE 'C'
END AS grade
FROM Student;
``` |

---

### **🔷 6. Other Utility Functions**

| **Function** | **Purpose** | **Example** |


|--------------|-------------|-------------|
| `COALESCE()` | Return first non-NULL value | `SELECT
COALESCE(middle_name,'N/A') FROM Person;` |
| `NULLIF()` | Return NULL if two values equal | `SELECT NULLIF(a,b);` |

You might also like