SQRT Function - SQL
Overview
The SQRT function in SQL returns the square root of a given numeric expression. It is useful for mathematical calculations involving square roots.
Example:
SELECT
SQRT(4)
Syntax:
SELECT
SQRT(numeric_expression)
numeric_expression
is the numeric value for which you want to calculate the square root.
Sample Data:
first_name | vacation_days |
---|---|
Frank | 5 |
Jane | 2 |
Ashley | 3 |
Glenn | -3 |
Kelly | 2 |
Richard | -7 |
George | 2 |
Kyle | 1 |
James | -2 |
Gustavo | -10 |
Example: Hard-coded value
In this example, we are returning the square root of the number 4, the final output is 2.
Example: Query without the WHERE Statement
In this example, we are returning the square root of the values in the vacation_days column.
Example: Query with the WHERE Statement
In this example, we are returning the square root of the values in the vacation_days column where the first_name column equals ‘Kelly.’