在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;
最新评论
本站CDN与莫名CDN同款、亚太CDN、速度还不错,值得推荐。
感谢推荐我们公司产品、有什么活动会第一时间公布!
我在用这类站群服务器、还可以. 用很多年了。