OceanBase RATIO_TO_REPORT
2021-06-25 15:28 更新
RATIO_TO_REPORT
函数计算一个值与一组值之和的比率。
语法
RATIO_TO_REPORT(expr) OVER ([query_partition_clause])
参数
参数 |
说明 |
---|---|
expr |
只能为正常数。 |
OVER |
使用 |
返回类型
返回数值型数据。
示例
根据部分展示员工产出占部门总展出的比例。建表 product,并向里面插入数据,执行以下语句:
CREATE TABLE product (name VARCHAR(8), deptno NUMBER, output NUMBER);
INSERT INTO product VALUES('Linda',100,5050);
INSERT INTO product VALUES('Tan',1001,8500);
INSERT INTO product VALUES('Tom',1001,3900);
INSERT INTO product VALUES('John',100,29500);
INSERT INTO product VALUES('Mery',1001,1500);
INSERT INTO product VALUES('Peter',100,1060);
COMMIT;
执行以下语句:
SELECT name, OUTPUT, deptno, RATIO_TO_REPORT(output) OVER (partition BY deptno) FROM product;
查询结果如下:
+-------+--------+--------+------------------------------------------------+
| NAME | OUTPUT | DEPTNO | RATIO_TO_REPORT(OUTPUT)OVER(PARTITIONBYDEPTNO) |
+-------+--------+--------+------------------------------------------------+
| Linda | 5050 | 100 | .1418140971637180567256388654872226902555 |
| John | 29500 | 100 | .8284189834316203313675933726481325470373 |
| Peter | 1060 | 100 | .0297669194046616119067677618646447627071 |
| Tan | 8500 | 1001 | .6115107913669064748201438848920863309353 |
| Tom | 3900 | 1001 | .2805755395683453237410071942446043165468 |
| Mery | 1500 | 1001 | .107913669064748201438848920863309352518 |
+-------+--------+--------+------------------------------------------------+
以上内容是否对您有帮助:
更多建议: