MySQL - Numeric Library Function

AVG(): The AVG function calculates the average of a given set of values. For example, suppose we have a table named "students" with a column "score" containing the scores of students in a test. We can calculate the average score using the AVG function as follows:

SELECT AVG(score) AS avg_score FROM students;

This query will return the average score of all the students.

 

CEIL(): The CEIL function is used to round a number up to the nearest integer. For example, suppose we have a number 3.6, and we want to round it up to the nearest integer. We can use the CEIL function as follows:

SELECT CEIL(3.6) AS rounded_value;

This query will return 4 as the rounded value.

 

COUNT(): The COUNT function is used to count the number of rows in a table or the number of items in a specified column. For example, suppose we have a table named "students" with columns "id" and "name". We can count the number of rows in the table using the COUNT function as follows:

SELECT COUNT(*) AS num_rows FROM students;

This query will return the number of rows in the students table.

 

FLOOR(): The FLOOR function is used to round a number down to the nearest integer. For example, suppose we have a number 3.6, and we want to round it down to the nearest integer. We can use the FLOOR function as follows:

SELECT FLOOR(3.6) AS rounded_value;

This query will return 3 as the rounded value.

 

MAX(): The MAX function is used to return the maximum value in a specified column. For example, suppose we have a table named "students" with a column "score" containing the scores of students in a test. We can find the maximum score using the MAX function as follows:

SELECT MAX(score) AS max_score FROM students;

This query will return the maximum score of all the students.

 

MIN(): The MIN function is used to return the minimum value in a specified column. For example, suppose we have a table named "students" with a column "score" containing the scores of students in a test. We can find the minimum score using the MIN function as follows:

SELECT MIN(score) AS min_score FROM students;

This query will return the minimum score of all the students.

 

ROUND(): The ROUND function is used to round a number to a specified number of decimal places. For example, suppose we have a number 3.678, and we want to round it to two decimal places. We can use the ROUND function as follows:

SELECT ROUND(3.678, 2) AS rounded_value;

 

RAND(): The rand() function in MySQL generates a random number between 0 and 1. Here's an example of how to use the rand() function in MySQL:

SELECT RAND();

This query will return a random number between 0 and 1, such as 0.456789.

 

ROUND(): The round() function in MySQL rounds a number to a specified number of decimal places. Here's an example of how to use the round() function in MySQL:

SELECT ROUND(5.6789, 2);

This query will return the number 5.68, which is 5.6789 rounded to 2 decimal places.

 

SUM(): The sum() function in MySQL calculates the sum of a column in a table. Here's an example of how to use the sum() function in MySQL:

SELECT SUM(column_name) FROM table_name;

This query will return the sum of the values in the column_name column of the table_name table. For example, if the column_name column contains the values 1, 2, and 3, the query will return 6.