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, 256🔥, 0💬
Popular Posts:
Where to find answers to frequently asked questions I am new to Oracle database. Here is a list of f...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
What Is ISAM in MySQL? ISAM (Indexed Sequential Access Method) was developed by IBM to store and ret...
How to run Queries with SQL Server Management Studio Express in SQL Server? 1. Launch and connect SQ...
Where to find answers to frequently asked questions on Managing Security, Login and User in SQL Serv...