Collections:
STDDEV_POP() - Population Standard Deviation
How to calculate the population standard deviation of a field expression in result set groups using the STDDEV_POP() function?
✍: FYIcenter.com
STDDEV_POP(expr) is a MySQL built-in aggregate function that calculates the population standard deviation of a field expression in result set groups. For example:
SELECT help_category_id, STDDEV_POP(help_topic_id), COUNT(help_topic_id) FROM mysql.help_topic GROUP BY help_category_id; -- +------------------+---------------------------+----------------------+ -- | help_category_id | STDDEV_POP(help_topic_id) | COUNT(help_topic_id) | -- +------------------+---------------------------+----------------------+ -- | 1 | 0.5 | 2 | -- | 2 | 10.254954004414309 | 35 | -- | 3 | 84.70569561304855 | 59 | -- | 4 | 0.5 | 2 | -- | 5 | 1.6996731711975943 | 3 | -- ... -- +------------------+---------------------------+----------------------+ SELECT help_category_id, help_topic_id FROM mysql.help_topic WHERE help_category_id = 5; -- +------------------+---------------+ -- | help_category_id | help_topic_id | -- +------------------+---------------+ -- | 5 | 40 | -- | 5 | 43 | -- | 5 | 44 | -- +------------------+---------------+
STDDEV_POP() is also a window function, you can call it with the OVER clause to calculate the population standard deviation of the given expression in the current window. For example:
SELECT help_topic_id, help_category_id, STDDEV_POP(help_topic_id) OVER w FROM mysql.help_topic WINDOW w AS (PARTITION BY help_category_id); -- +---------------+------------------+----------------------------------+ -- | help_topic_id | help_category_id | STDDEV_POP(help_topic_id) OVER w | -- +---------------+------------------+----------------------------------+ -- | 0 | 1 | 0.5 | -- | 1 | 1 | 0.5 | -- | 2 | 2 | 10.254954004414309 | -- | 6 | 2 | 10.254954004414309 | -- | 7 | 2 | 10.254954004414309 | -- | 8 | 2 | 10.254954004414309 | -- | 9 | 2 | 10.254954004414309 | -- ... -- +---------------+------------------+----------------------------------+
Reference information of the STDDEV_POP() function:
STDDEV_POP(expr): std Returns the population standard deviation of expr (the square root of VAR_POP()). If there are no matching rows, STDDEV_POP() returns NULL. Arguments, return value and availability: expr: Required. The field expression in result set groups. std: Return value. The population standard deviation of the input expression. Available since MySQL 5.7.
Related MySQL functions:
⇒ STDDEV_SAMP() - Sample Standard Deviation
⇐ STDDEV() - Synonym for STDDEV_POP()
2023-11-18, 263🔥, 0💬
Popular Posts:
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
Where to find answers to frequently asked questions on Downloading and Installing SQL Server 2005 Ex...
How To Enter Unicode Character String Literals in SQL Server Transact-SQL? Unicode characters are mu...
What Is Program Global Area (PGA) in Oracle? A Program Global Area (PGA) is a memory buffer that is ...
How To Select All Columns of All Rows from a Table with a SELECT statement in SQL Server? The simple...