SQL Server 中的均值和众数
平均值是通过将总和除以数据集中值的数量计算得出的给定数据集的平均值。
例子:
Input: 1, 2, 3, 4, 5
Output: 3
Explanation:
sum = 1 + 2 + 3 + 4 + 5 = 15
number of values = 5
mean = 15 / 5 = 3
查询以查找表中的均值
SELECT Avg(Column_Name)
FROM Table_Name
例子:
创建表:
表格内容:
查询求平均值:
数据集的众数是一系列数据中出现频率最高的值。
例子:
Input: 1, 2, 2, 3, 4, 4, 4, 5, 5, 6
Output: 4
Explanation:
2 occurs 2 times, 5 occurs 2 times
4 occurs 3 times and rest other
occurs 1 time
So, 4 occurs most frequently and
is thus the output.
查询在表中查找模式
SELECT TOP 1 Column_Name
FROM Table_name
GROUP BY [Column_Name]
ORDER BY COUNT(*) DESC
例子:
创建表:
表格内容:
查询查找模式: