MySQL STDDEV_POP is one of the Aggregate Functions, which calculates the Standard Deviation of total records (or rows) selected by the SELECT Statement. The mathematical formulas behind the STDDEV_POP to calculate the standard deviation are as shown below:

--Calculating the Mean or Average
Mean = Sum of each individual/Total number of items

--Calculating the Variance
Variance = ((OriginalValue – Mean)² + (OriginalValue – Mean)² +.... )/( Total number of items )

--Calculating Standard Deviation
Standard Deviation = Square root (Variance)

The MySQL STD and STDDEV Functions are synonyms for the standard STDDEV_POP function. So, you can use any of these function names.

The basic syntax behind the STD, STDDEV, and STDDEV_POP in MySQL is as shown below:

-- STD example
SELECT STD(Column_Name)
FROM Source;

-- STDDEV example
FROM Source;

-- STDDEV_POP example
FROM Source;

In this article, we show you, How to write MySQL STD, STDDEV, and STDDEV_POP functions to calculate the Standard Deviation with an example. For this, We are going to use the below-shown data

Customer Table 1


In STD, STDDEV, and STDDEV_POP functions simply return the Standard Deviation of the total number of records present in the specified column. For example, the below query calculates the Standard Deviation of total records present in the Yearly_Income column from 

-- STD example
SELECT STD(Yearly_Income) AS `Standard income`
FROM customerdetails;

-- STDDEV example
SELECT STDDEV(Yearly_Income) AS `Standard income`
FROM customerdetails;

-- STDDEV_POP example
SELECT STDDEV_POP(Yearly_Income) AS `Standard income`
FROM customerdetails;
MySQL STD, STDDEV, and STDDEV_POP Functions Example 1

STDDEV_POP Group By Example

In general, we use this STDDEV_POP function to calculate the Standard Deviation of products belonging to a particular category or color, etc.

In these situations, we can use the GROUP BY Clause to group the products by color or category. And then, we use STDDEV_POP Function to calculate the Standard Deviation of products present in each group. Let us see the Aggregate Function Example.

-- STDDEV_POP Function Example
USE company;
SELECT  Profession,
FROM customerdetails
GROUP BY Profession;

Above MySQL Query groups the Customers by their Profession and calculates their Standard Deviation.

MySQL STD, STDDEV, and STDDEV_POP Functions Example 2

We are taking the Software Developer profession and showing you the SELECT Statement output.

–Calculating Mean
Mean = (70000 + 79000) / 2
Mean = 74500

–Calculating Variance
Variance = ( (70000 – 74500)² + (79000 – 74500) )² / 2
Variance = 20,250,000

–Calculating Standard Deviation
Standard Deviation = SQRT (Variance)
Standard Deviation = SQRT (20,250,000)
which means, Standard Deviation = 4500

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.