📜  MySQL 中的 STDDEV_POP()函数

📅  最后修改于: 2022-05-13 01:54:44.586000             🧑  作者: Mango

MySQL 中的 STDDEV_POP()函数

STDDEV_POP() :
MySQL 中的该函数用于计算表达式的总体标准差。

句法 :

STDDEV_POP(expr);

范围 :
该方法只接受一个参数。

  • 表达式 –
    我们要从中计算总体标准差的输入表达式。

回报:
它返回总体标准差。

示例-1:
使用 STDDEV_POP函数从给定的 Player 表中查找 RunScored 列的总体标准偏差。

创建玩家表:

CREATE TABLE Player  
(
PlayerId INT AUTO_INCREMENT,  
PlayerName VARCHAR(100) NOT NULL,
RunScored INT NOT NULL,
WicketsTaken INT NOT NULL,
PRIMARY KEY(PlayerId)
);

插入数据到表中:

INSERT INTO Player  
(PlayerName, RunScored,  WicketsTaken )
VALUES
('KL Rahul', 52, 0 ),
('Hardik Pandya', 30, 1 ),
('Ravindra Jadeja', 18, 2 ),
('Washington Sundar', 10, 1),
('D Chahar', 11, 2 ),  
('Mitchell Starc', 0, 3);

要验证使用以下命令如下。

SELECT  * from Player ;

输出 :

PLAYERIDPLAYERNAMERUNSCOREDWICKETSTAKEN
1KL Rahul520
2Hardik Pandya301
3Ravindra Jadeja182
4Washington Sundar101
5D Chahar112
6Mitchell Starc03

现在,我们将找到 RunScored 列的总体标准差。

SELECT  STDDEV_POP(RunScored ) 
as Pop_Standard_Deviation 
FROM Player ;

输出 :

POP_STANDARD_DEVIATION
16.87618308609964

示例 2 :
现在,我们将找到 WicketsTaken 列的总体标准差。

SELECT  STDDEV_POP(WicketsTaken) 
as Pop_Std_Dev_Wickets   
FROM Player ;

输出 :

POP_STD_DEV_WICKETS
0.9574271077563381

示例 3 :
在此示例中,我们将查找在“Kolkata”位置工作的员工收入的总体标准差,以演示创建名为 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 )
);

插入数据到表中:

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 ) ;

要验证使用以下命令如下。

Select * FROM EmployeeDetails;

输出 :

EMPLOYEE_IDEMPLOYEE_NAMEWORKING_ATWORK_LOCATIONJOINING_DATEANNUAL_INCOME
1Amit KhanXYZ DigitalKolkata2019-10-06350000 
2Shreetama PalABC Corp.Kolkata2018-12-16500000
3Aniket SharmaPQR Soln.Delhi2020-01-11300000 
4Maitree JanaXYZ DigitalKolkata2019-05-01400000 
5Priyanka OjhaABC Corp.Delhi2019-02-13350000
6Sayani MitraXYZ DigitalKolkata2019-09-15320000 
7Nitin DeyPQR Soln.Delhi2019-10-06250000 
8Sujata SamantaPQR Soln.Kolkata2020-10-06350000 
9Sudip MajhiABC Corp.Delhi2018-10-30600000 
10Sanjoy KohliXYZ DigitalDelhi2019-04-18450000 

现在,我们将找到工作地点为“加尔各答”的员工的年收入的总体标准差。

SELECT  'Kolkata' AS 'Work_Location',
STDDEV_POP(Annual_Income) as PopStdDevOfAnnualIncome  
FROM EmployeeDetails where Work_Location = 'Kolkata';

输出 :

WORK_LOCATIONPOPSTDDEVOFANNUALINCOME
Kolkata 63435.006108614834