STDDEV() function in MySQL
Last Updated :
30 Dec, 2020
Sometimes we need to calculate population Standard deviation of an expression in MySQL.
STDDEV() function can be used for this purpose in MySQL. It returns NULL if no matching rows found in the given expression.
Syntax :
STDDEV(expr);
Parameter : This method accepts only one parameter.
-
expr : Input expression from which we want to calculate standard deviation .
Returns : It returns the population standard deviation.
Example-1 :
Finding standard deviation of sub1mark column from the given StudentMarks table using STDDEV Function.
Creating a StudentMarks table :
CREATE TABLE StudentMarks
(
StudentId INT AUTO_INCREMENT,
StudentName VARCHAR(100) NOT NULL,
Roll INT NOT NULL,
Sub1Mark INT NOT NULL,
Sub2Mark INT NOT NULL,
Sub3Mark INT NOT NULL,
TotalMarks INT NOT NULL,
PRIMARY KEY(StudentId )
);
Inserting data into the Table :
INSERT INTO StudentMarks
(StudentName, Roll, Sub1Mark, Sub2Mark, Sub3Mark, TotalMarks)
VALUES
('Amit Jana', 10100, 85, 80, 95, 260),
('Labanya Mallick', 11000, 81, 89, 95, 265),
('Virat Sharma', 12000, 75, 83, 90, 248),
('Sayani Samanta', 13000, 95, 90, 99, 284),
('Riyanka Panda', 14000, 70, 87, 88, 245),
('Ritika Shah', 15000, 78, 89, 90, 257);
To verify used the following command as follows.
SELECT * from StudentMarks;
Output :
STUDENTID |
STUDENTNAME |
ROLL |
SUB1MARK |
SUB2MARK |
SUB3MARK |
TOTALMARKS |
1 |
Amit Jana |
10100 |
85 |
80 |
95 |
260 |
2 |
Labanya Mallick |
11000 |
81 |
89 |
95 |
265 |
3 |
Virat Sharma |
12000 |
75 |
83 |
90 |
248 |
4 |
Sayani Samanta |
13000 |
95 |
90 |
99 |
284 |
5 |
Riyanka Panda |
14000 |
70 |
87 |
88 |
245 |
6 |
Ritika Shah |
15000 |
78 |
89 |
90 |
257 |
Now we are going to find standard deviation of sub1mark column.
SELECT STDDEV(Sub1Mark) as Sub1StandardDeviation
FROM StudentMarks;
Output :
SUB1STANDARDDEVIATION |
7.930251502246881 |
Example-2
Now we are going to find population standard deviation of total marks column.
SELECT STDDEV(TotalMarks) as StdDevOfTotalMarks
FROM StudentMarks;
Output :
STDDEVOFTOTALMARKS |
12.772583485297279 |
Example-3 : In this example we are going to find the population standard deviation of Income of Employee who are working in the company 'XYZ Digital'. To demonstrate create a table named
EmloyeeDetails.
CREATE TABLE EmployeeDetails(
Employee_Id INT AUTO_INCREMENT,
Employee_Name VARCHAR(100) NOT NULL,
Working_At VARCHAR(20) NOT NULL,
Work_Location VARCHAR(20) NOT NULL,
Joining_Date DATE NOT NULL,
Annual_Income INT NOT NULL,
PRIMARY KEY(Employee_Id )
);
Inserting data into the Table :
INSERT INTO
EmployeeDetails(Employee_Name, Working_At, Work_Location, Joining_Date, Annual_Income )
VALUES
('Amit Khan', 'XYZ Digital', 'Kolkata', '2019-10-06', 350000 ),
('Shreetama Pal', 'ABC Corp.', 'Kolkata', '2018-12-16', 500000 ),
('Aniket Sharma', 'PQR Soln.', 'Delhi', '2020-01-11', 300000 ),
('Maitree Jana', 'XYZ Digital', 'Kolkata', '2019-05-01', 400000 ),
('Priyanka Ojha', 'ABC Corp.', 'Delhi', '2019-02-13', 350000 ),
('Sayani Mitra', 'XYZ Digital', 'Kolkata', '2019-09-15', 320000 ),
('Nitin Dey', 'PQR Soln.', 'Delhi', '2019-10-06', 250000 ),
('Sujata Samanta', 'PQR Soln.', 'Kolkata', '2020-10-06', 350000 ),
('Sudip Majhi', 'ABC Corp.', 'Delhi', '2018-10-30', 600000 ),
('Sanjoy Kohli', 'XYZ Digital', 'Delhi', '2019-04-18', 450000 ) ;
To verify used the following command as follows.
Select * FROM EmployeeDetails;
Output :
EMPLOYEE_ID |
EMPLOYEE_NAME |
WORKING_AT |
WORK_LOCATION |
JOINING_DATE |
ANNUAL_INCOME |
1 |
Amit Khan |
XYZ Digital |
Kolkata |
2019-10-06 |
350000 |
2 |
Shreetama Pal |
ABC Corp. |
Kolkata |
2018-12-16 |
500000 |
3 |
Aniket Sharma |
PQR Soln. |
Delhi |
2020-01-11 |
300000 |
4 |
Maitree Jana |
XYZ Digital |
Kolkata |
2019-05-01 |
400000 |
5 |
Priyanka Ojha |
ABC Corp. |
Delhi |
2019-02-13 |
350000 |
6 |
Sayani Mitra |
XYZ Digital |
Kolkata |
2019-09-15 |
320000 |
7 |
Nitin Dey |
PQR Soln. |
Delhi |
2019-10-06 |
250000 |
8 |
Sujata Samanta |
PQR Soln. |
Kolkata |
2020-10-06 |
350000 |
9 |
Sudip Majhi |
ABC Corp. |
Delhi |
2018-10-30 |
600000 |
10 |
Sanjoy Kohli |
XYZ Digital |
Delhi |
2019-04-18 |
450000 |
Now we are going to find population standard deviation of annual Income for those Employee who are working in 'XYZ Digital'.
SELECT STDDEV(Annual_Income) as StdDevOfAnnualIncome
FROM EmployeeDetails where WORKING_AT = 'XYZ Digital';
Output :
STDDEVOFANNUALINCOME |
49497.474683058324 |
Similar Reads
STD() function in MySQL
With the help of STD() function we can calculate population Standard deviation of an expression in MySQL. But, if there are no matching rows in the given expression it returns Null. Syntax : STD(expr); Parameter : This method accepts only one parameter. expr : Input expression from which we want to
3 min read
STDDEV_POP() function in MySQL
STDDEV_POP() : This function in MySQL is used to calculate population standard deviation of an expression. Syntax : STDDEV_POP(expr); Parameter : This method accepts only one parameter. expr - Input expression from which we want to calculate population standard deviation. Returns : It returns the po
3 min read
STDDEV_SAMP() function in MySQL
STDDEV_SAMP() function in MySQL is used to calculate sample standard deviation of an expression. Syntax : STDDEV_SAMP(expr); Parameter : This method accepts only one parameter. expr : Input expression from which we want to calculate sample standard deviation. Returns : It returns the population stan
3 min read
SQRT() Function in MySQL
The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications.In the article, we will cover
3 min read
TIME() Function in MySQL
The TIME() function in MySQL is used to extract the time portion from a date or datetime expression, returning the time in the format 'HH:MM'. This function is particularly useful when working with time components in databases, such as scheduling or logging systems. In this article, We will learn ab
4 min read
SOUNDEX() Function in MySQL
SOUNDEX() function in MySQL is used to return a phonetic representation of a string. The phonetic represents the way the string will sound. The SOUNDEX function helps to compare words that are spelled differently, but sound alike in English. Syntax : SOUNDEX(str) Parameter : SOUNDEX() function accep
3 min read
SYSDATE() function in MySQL
SYSDATE() function in MySQL is used to return the current date and time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu format depending on the context of the function. Syntax : SYSDATE() Parameter : This method does not accept any parameter. Returns : It returns the current date and time value. Exa
1 min read
SPACE() Function in MySQL
SPACE() function in MySQL is used to return a string consisting of specified empty space characters. Syntax : SPACE(num) Parameter : This method accepts one parameter as mentioned above and described below : num : It is an integer which indicates how many spaces are being contained. Returns : It ret
1 min read
ORD() Function in MySQL
ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from
3 min read
TAN() Function in MySQL
TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
1 min read