SQL Server STDEV Function
Let us explore!
SQL Server Stdev() Function Syntax and Parameters
The following shows the syntax of the stdev() function:
The function arguments are expressed in the following:
- ALL – This parameter allows the function to be applied to all provided values. By default, the function is applied to ALL.
- DISTINCT – If specified, this function is only applied to unique values.
- Expression – Refers to a numeric expression. The value of this parameter cannot be an aggregate function or a subquery.
The function returns a floating point value, denoting the standard deviation for the given set of values.
Example Usage:
The following examples demonstrate how to use the stdev() function in SQL Server:
Example 1: Using the Stdev Function
The following illustrations show the stdev function’s usage on an SQL Server table. The original table is as shown:
We can calculate the standard deviation of the values in the price column as shown in the following query:
This should return the resulting standard deviation as follows:
------------------+
1026.9104843447374|
As mentioned, the function calculates the standard deviation of all the values in the provided column.
Suppose we have a table with duplicate values as shown in the following:
If we calculate the standard deviation of the previous table, use the following command:
The resulting standard deviation value is as follows:
-----------------+
993.4328361796786|
We can exclude the duplicate values as shown in the following:
The resulting value is as follows:
------------------+
1026.9104843447374|
Conclusion
In this post, you learned how to use the stdev() function in the SQL Server to calculate the standard deviation for a given set of values.
Thanks for reading!
Source: linuxhint.com