SQL Mathematical functions

The SQL Mathematical functions

SQL Mathematical functions allow you to perform mathematical operations on data within queries in sql. These functions help with calculations and data manipulation.

Use of SQL Mathematical Functions:

Data Manipulation: To perform calculations on stored data.
Aggregation: To compute aggregate functions for statistical analysis.
Data Transformation: To modify and transform numeric values.
Data Generation: To generate numeric values or perform complex calculations within queries.

Below are the SQL mathematical functions with examples

  1. ABS() – Absolute Value:
    Returns positive value of a number.
    Example: SELECT ABS(-10);
    Result 10
  2. ROUND() – Round a Number:
    Rounds a specified number of decimal places.
    Example: SELECT ROUND(25.637, 2);
    Result 25.64
  3. CEILING() – Round Up:
    Rounds a number up to the nearest integer.
    Example: SELECT CEILING(15.23);
    Result 16
  4. FLOOR() – Round Down:
    Rounds a number down to the nearest integer.
    Example: SELECT FLOOR(15.78);
    Result 15
  5. SQRT() – Square Root:
    Calculates the square root of a number.
    Example: SELECT SQRT(25);
    Result 5
  6. POWER() – Exponential Power:
    Raises a number to the specified power.
    Example: SELECT POWER(2, 3);
    Result 8
  7. MOD() – Modulo Operation:
    Returns the remainder of a division operation.
    Example: SELECT MOD(15, 4);
    Result 3
  8. RAND() – Random Number:
    Generates a random decimal number between 0 and 1.
    Example: SELECT RAND();
  9. SIGN() – Sign of a Number:
    Returns the sign of a number (-1 for negative, 0 for zero, 1 for positive).
    Example: SELECT SIGN(-25);
    Result -1
  10. PI() value of Pi:
    Returns the value of Pi (π).
    Example: SELECT PI();
    Result approximately 3.14159

These SQL mathematical functions are useful for various calculations within SQL queries, facilitating numeric operations and transformations on data stored in databases.

Types of SQL Mathematical Functions

  • Arithmetic Functions
  • Trigonometric Functions
  • Exponential Functions
  • Round and Absolute Functions
  • Square Root Function
  • Power Function
  • Ceiling and Floor Functions
  • Modulus Function

Mathematical functions in SQL are operations used for mathematical calculations within SQL queries. These functions enable users to perform various mathematical computations on data stored in a database. They help in manipulating numeric values and generating calculated results.

Arithmetic Functions:
Addition (+), Subtraction (-), Multiplication (*), Division (/):
Perform basic arithmetic operations on numeric data in SQL queries.

Trigonometric Functions:
SIN(), COS(), TAN():
Calculate the trigonometric values (sine, cosine, and tangent) of an angle specified in radians.
ASIN(), ACOS(), and ATAN():
Compute inverse trigonometric values, returning angles in radians.

Exponential Functions:
EXP():
Returns the exponential value of a specified number.
LOG(), LOG10():
Calculate logarithmic values with base e and base 10, respectively.

Round and Absolute Functions:
ROUND():
Round numeric values to a specific decimal place.
ABS():
Return the absolute (positive) value of a number.

Square Root Function:
SQRT():
Computes the square root of a given number.

Power Function:
POWER():
Raises a number to a specified power.

Ceiling and Floor Functions:
CEILING():
Rounds a no. up to the nearest integer.
FLOOR():
Rounds a no. down to the nearest integer.

Modulus Function:
MOD():
Computes the remainder of a division operation.

These functions are fundamental for numeric operations, computations, and transformations, facilitating various mathematical tasks within the database management system.

Leave a Comment