![]() |
VOOZH | about |
SQL provides a variety of advanced functions for performing complex calculations, transformations and aggregations on data. These functions are essential for data analysis, reporting, and efficient database management.
Aggregate functions perform calculations on multiple rows and return a single value.
SELECT COUNT(*), AVG(Salary), SUM(Salary), MIN(Salary), MAX(Salary)
FROM Employees;Output :
Returns count of rows, average, total salary, min salary, and max salary.Conditional functions help apply logic inside SQL queries.
SELECT Name,
CASE WHEN Salary > 5000 THEN 'High'
ELSE 'Low' END AS Salary_Level
FROM Employees;Output:
Labels employees as High or Low salary.Mathematical functions are used for numeric calculations. Some commonly used mathematical functions are given below:
SELECT ABS(-15), ROUND(25.678, 2), POWER(2, 3), SQRT(49);Output :
15, 25.68, 8, 7Beyond aggregates and math, SQL offers system and utility functions for deeper insights.
Convert decimal to binary
SELECT BIN(18);Output:
Convert to binary string
SELECT BINARY "GeeksforGeeks";Output:
Returns the first non-null expression in a list
SELECT COALESCE(NULL,NULL,'GeeksforGeeks',NULL,'Geeks');Output:
Returns the unique connection ID for the current connection
SELECT CONNECTION_ID();Output:
Returns the user name and hostname for the MySQL account used by the server.
SELECT CURRENT_USER();Output:
Returns the name of the default database.
SELECT DATABASE();Output:
Returns one value if a condition is TRUE, or another value if a condition is FALSE
SELECT IF(200<500, "YES", "NO");Output:
Returns the first AUTO_INCREMENT value that was set by the most recent INSERT or UPDATE statement
SELECT LAST_INSERT_ID();Output:
Returns NULL if equal
SELECT NULLIF(115, 115);Output:
Returns the user name and host name for the current MySQL user
SELECT SESSION_USER();Output:
Returns the user name and host name for the current MySQL user.
SELECT SYSTEM_USER();Output:
It returns the user name and host name for the current MySQL user
SELECT USER();Output:
It returns the version of the MySQL database
SELECT VERSION();Output: