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, 1108🔥, 0💬
Popular Posts:
What To Do If the StartDB.bat Failed to Start the XE Instance in Oracle? If StartDB.bat failed to st...
Where to find answers to frequently asked questions on Downloading and Installing SQL Server 2005 Ex...
How To Calculate Age in Days, Hours and Minutes in SQL Server Transact-SQL? On many Web sites, news ...
How To Divide Query Output into Multiple Groups with the GROUP BY Clause in SQL Server? Sometimes, y...
Where to find answers to frequently asked questions on Storage Engines: MyISAM, InnoDB and BDB in My...