在Oracle数据库中,有许多常用的统计函数可以帮助我们进行数据分析,这些函数简单易用,可以快速地获取所需的统计数据,以下是一些常用的统计函数及其功能:
1、COUNT(*)
用途:计算表中的记录数。
语法:SELECT COUNT(*) FROM table_name;
2、SUM(column_name)
用途:计算指定列的总和。
语法:SELECT SUM(column_name) FROM table_name;
3、AVG(column_name)
用途:计算指定列的平均值。
语法:SELECT AVG(column_name) FROM table_name;
4、MIN(column_name)
用途:计算指定列的最小值。
语法:SELECT MIN(column_name) FROM table_name;
5、MAX(column_name)
用途:计算指定列的最大值。
语法:SELECT MAX(column_name) FROM table_name;
6、GROUP BY
用途:根据指定的列对数据进行分组。
语法:SELECT column_name, function_name(column_name) FROM table_name GROUP BY column_name;
7、HAVING
用途:对分组后的数据进行筛选。
语法:SELECT column_name, function_name(column_name) FROM table_name GROUP BY column_name HAVING condition;
8、RANK() OVER (ORDER BY column_name)
用途:为排序后的记录分配排名。
语法:SELECT column_name, RANK() OVER (ORDER BY column_name) AS rank FROM table_name;
9、DENSE_RANK() OVER (ORDER BY column_name)
用途:为排序后的记录分配排名,相同值的记录具有相同的排名。
语法:SELECT column_name, DENSE_RANK() OVER (ORDER BY column_name) AS dense_rank FROM table_name;
10、NTILE(n) OVER (ORDER BY column_name)
用途:将排序后的记录分为n个组。
语法:SELECT column_name, NTILE(n) OVER (ORDER BY column_name) AS ntile FROM table_name;
11、PERCENTILE_CONT(percentile) WITHIN GROUP (ORDER BY column_name) OVER () AS percentile_cont
用途:计算指定百分位数的值。
语法:SELECT PERCENTILE_CONT(percentile) WITHIN GROUP (ORDER BY column_name) OVER () AS percentile_cont FROM table_name;
12、PERCENTILE_DISC(percentile) WITHIN GROUP (ORDER BY column_name) OVER () AS percentile_disc
用途:计算指定百分位数的值,与PERCENTILE_CONT不同,PERCENTILE_DISC返回的是离散值。
语法:SELECT PERCENTILE_DISC(percentile) WITHIN GROUP (ORDER BY column_name) OVER () AS percentile_disc FROM table_name;
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/516301.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复