ratio_to_report分析函数求占比
drop table test;
create table test
(
name varchar(20),
kemu varchar(20),
score number
);
insert into test values('testa','yuwen',10);
insert into test values('testa','英语',100);
insert into test values('testb','yuwen',60);
insert into test values('testb','yuwen',120);
insert into test values('testc','yuwen',40);
select name,
score,
ratio_to_report(score) over() as "占所有科目的百分比",
ratio_to_report(score) over(partition by kemu) as "占各科目的百分比"
from test ;
NAME SCORE 占所有科目的百分比 占各科目的百分比
-------------------- ---------- ------------------ ----------------
testa 10 .03030303 .043478261
testb 60 .181818182 .260869565
testc 40 .121212121 .173913043
testb 120 .363636364 .52173913
testa 100 .303030303 1
drop table test;
试想下假设我们没有这个分析函数,实现就有可能如下:
select name,score,
(score/sum(score) over()) as "占所有科目的百分比",
(score/sum(score) over(partition by kemu)) as "占所有科目的百分比"
from test
group by name,score,kemu
order by 2;
嘿嘿,还是没有那个方便,估计效率也不咋的。
总结:1. 有了ratio_to_report分析函数,我们避免了还需要写分析函数,自己相除的写法,SQL简单实现了。
2. site:download.oracle.com ratio_to_report 搜索oracle官方文档
ratio_to_report分析函数求占比的更多相关文章
- ratio_to_report 分析函数求占比
drop table test; create table test ( name varchar(20), kemu varchar(20), score number ); insert int ...
- nulls last ratio_to_report(id) over() 占比函数
ORDER BY t3.pctl DESC NULLS LAST http://blog.itpub.net/9932141/viewspace-600751/ http://blog.csdn.n ...
- oracle 分析函数
认识分析函数 分析函数是什么? 分析函数是oracle专门用于解决复杂报表统计需求的功能强大的函数,它可以在数据中进行分组然后计算基于组的某种统计值,并且每一组的每一行都可以返回一个统计值. 分析函数 ...
- SQL优化一
1.行列转换: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值); select decode(sign(变量1-变量2),-1,变量1,变量2) from dual ...
- SQL优化一(SQL使用技巧)
1.行列转换: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值); select decode(sign(变量1-变量2),-1,变量1,变量2) from dual ...
- 瘋子C++笔记
瘋耔C++笔记 欢迎关注瘋耔新浪微博:http://weibo.com/cpjphone 参考:C++程序设计(谭浩强) 参考:http://c.biancheng.net/cpp/biancheng ...
- C++笔试题库-------Coding整理
1. 反转字符串 char* strrev1(const char* str) { int len = strlen(str); ]; char *p = temp + len; *p = '\0'; ...
- Flex中宽度计算
flex 有三个属性值,分别是 flex-grow, flex-shrink, flex-basis,默认值是 0 1 auto. 发现网上详细介绍他们的文章比较少, 今天就详细说说他们,先一个一个看 ...
- 弹性盒子模型属性之flex-shrink
上一次,我们已经了解过flex-grow的具体用法后,这周,让我们一起来见一下flex-basis这个属性. flex-shrink 定义项目的缩小比例,默认值为1,注意前提是空间不足的情况下,项目缩 ...
随机推荐
- Lightoj1093 【线段树】
题意: 给出n个数,然后对于D区间的数求一个最大差值 思路: 区间最大最小...我居然没想到线段树... #include <bits/stdc++.h> using namespace ...
- 如何在内网打洞使得能暴露mstsc端口
说明: 1.目标机器Target,有全部控制权,其所处网络无法向外网暴露端口,但是已知Target的外网地址:Target_internet_addr 2.交换机器Exchange,有全部控制权,其所 ...
- [Xcode 实际操作]九、实用进阶-(17)使用CGBlendMode改变UIImage颜色,实现对图片进行混合着色
目录:[Swift]Xcode实际操作 本文将演示如何使用CGBlendMode改变UIImage颜色,实现对图片进行混合着色. 在项目文件夹[DemoApp]上点击鼠标右键 ->[New Fi ...
- Mol Cell Proteomics. |彭建祥| 人胃肠道间质瘤亚群蛋白质组图谱
大家好,本周分享的是发表在Molecular & Cellular Proteomics 上的一篇关于人胃肠道间质瘤亚群蛋白质组图谱的文章,题目是Proteomic maps of human ...
- get 和 post 请求的区别(转)
转自 http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html http://www.nowamagic.net/librarys/ve ...
- 最长上升序列(Lis)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
- 「今日 GitHub 趋势」让全世界程序员体会中国的 12306 抢票狂潮
[2018年1月7日 GitHub 趋势] No.1:yyx990803 / build-your-own-mint 单日 714 星 使用 Plaid,Google 表格和 CircleCI 构建您 ...
- Turtles (非纯分块)
http://codeforces.com/contest/103/problem/D #include <bits/stdc++.h> using namespace std; type ...
- iOS开发 - CocoaPods的常见使用方式
1 CocoaPods 的安装 1.1 作用: 帮助管理和维护第三方框架,快速的搜索到第三方框架, 然后自动集成到工程里面来, 并编译成一个libPod.a的静态库给我们项目用 1.2 理解: 1. ...
- Centos 5.11 升级 Openssl
由于Openssl版本较低,故此升级版本来解决一些小问题. 1:查看openssl版本: [root@server-008 ~]# openssl versionOpenSSL 0.9.8e-fips ...