SQL SQRT Function

Example

Return the square root of a number:

SELECT SQRT(64);

Definition and Usage

The SQRT() function returns the square root of a number.

Syntax

SQRT(number)

Continue reading SQL SQRT Function

SQL SIGN Function

Example

Return the sign of a number:

SELECT SIGN(255.5);

Definition and Usage

The SIGN() function returns the sign of a number.

This function will return one of the following:

  • If number > 0, it returns 1
  • If number = 0, it returns 0
  • If number < 0, it returns -1

Syntax

SIGN(number)

Continue reading SQL SIGN Function

SQL ROUND Function

Example

Round the number to 2 decimal places:

SELECT ROUND(235.415, 2) AS RoundValue;

Definition and Usage

The ROUND() function rounds a number to a specified number of decimal places.

Tip: Also look at the FLOOR() and CEILING() functions.

Syntax

ROUND(number, decimals, operation)

Continue reading SQL ROUND Function

SQL RAND Function

Example

Return a random decimal number (no seed value – so it returns a completely random number >= 0 and <1):

SELECT RAND();

Definition and Usage

The RAND() function returns a random number between 0 (inclusive) and 1 (exclusive).

Syntax

RAND(seed)

Continue reading SQL RAND Function

SQL POWER Function

Example

Return 4 raised to the second power:

SELECT POWER(4, 2);

Definition and Usage

The POWER() function returns the value of a number raised to the power of another number.

Syntax

POWER(a, b)

Continue reading SQL POWER Function

SQL PI Function

Example

Return the value of PI:

SELECT PI();

Definition and Usage

The PI() function returns the value of PI.

Note: Also look at the DEGREES() and RADIANS() functions.

Syntax

PI()

Continue reading SQL PI Function

SQL MIN Function

Example

Find the price of the cheapest product in the “Products” table:

SELECT MIN(Price) AS SmallestPrice FROM Products;

Definition and Usage

The MIN() function returns the minimum value in a set of values.

Note: Also look at the MAX() function.

Syntax

MIN(expression)

Continue reading SQL MIN Function

SQL MAX Function

Example

Find the price of the most expensive product in the “Products” table:

SELECT MAX(Price) AS LargestPrice FROM Products;

Definition and Usage

The MAX() function returns the maximum value in a set of values.

Note: Also look at the MIN() function.

Syntax

MAX(expression)

Continue reading SQL MAX Function