SAMPLE:下例计算1998年每月销售的累积总体和样本变量(本例在SH用户下运行)
SELECT t.calendar_month_desc, VAR_POP(SUM(s.amount_sold)) OVER (ORDER BY t.calendar_month_desc) "Var_Pop", VAR_SAMP(SUM(s.amount_sold)) OVER (ORDER BY t.calendar_month_desc) "Var_Samp" FROM sales s, times t WHERE s.time_id = t.time_id AND t.calendar_year = 1998 GROUP BY t.calendar_month_desc;
CALENDAR Var_Pop Var_Samp -------- ---------- ---------- 1998-01 0 1998-02 6.1321E+11 1.2264E+12 1998-03 4.7058E+11 7.0587E+11 1998-04 4.6929E+11 6.2572E+11 1998-05 1.5524E+12 1.9405E+12 1998-06 2.3711E+12 2.8453E+12 1998-07 3.7464E+12 4.3708E+12 1998-08 3.7852E+12 4.3260E+12 1998-09 3.5753E+12 4.0222E+12 1998-10 3.4343E+12 3.8159E+12 1998-11 3.4245E+12 3.7669E+12 1998-12 4.8937E+12 5.3386E+12
VAR_SAMP
|
功能描述:(Variance Sample)该函数返回非空集合的样本变量(忽略null),VAR_POP进行如下计算:
(SUM(expr*expr)-SUM(expr)*SUM(expr)/COUNT(expr))/(COUNT(expr)-1)
SAMPLE:下例计算1998年每月销售的累积总体和样本变量
SELECT t.calendar_month_desc, VAR_POP(SUM(s.amount_sold)) OVER (ORDER BY t.calendar_month_desc) "Var_Pop", VAR_SAMP(SUM(s.amount_sold)) OVER (ORDER BY t.calendar_month_desc) "Var_Samp" FROM sales s, times t WHERE s.time_id = t.time_id AND t.calendar_year = 1998 GROUP BY t.calendar_month_desc;
CALENDAR Var_Pop Var_Samp -------- ---------- ---------- 1998-01 0 1998-02 6.1321E+11 1.2264E+12 1998-03 4.7058E+11 7.0587E+11 1998-04 4.6929E+11 6.2572E+11 1998-05 1.5524E+12 1.9405E+12 1998-06 2.3711E+12 2.8453E+12 1998-07 3.7464E+12 4.3708E+12 1998-08 3.7852E+12 4.3260E+12 1998-09 3.5753E+12 4.0222E+12 1998-10 3.4343E+12 3.8159E+12 1998-11 3.4245E+12 3.7669E+12 1998-12 4.8937E+12 5.3386E+12
VARIANCE
|
功能描述:该函数返回表达式的变量,Oracle计算该变量如下:
如果表达式中行数为1,则返回0
如果表达式中行数大于1,则返回VAR_SAMP
SAMPLE:下例返回部门30按雇佣日期排序的薪水值的累积变化
SELECT last_name, salary, VARIANCE(salary) OVER (ORDER BY hire_date) "Variance" FROM employees WHERE department_id = 30;
LAST_NAME SALARY Variance ------------------------- ---------- ---------- Raphaely 11000 0 Khoo 3100 31205000 Tobias 2800 21623333.3 Baida 2900 16283333.3 Himuro 2600 13317000 Colmenares 2500 11307000 |
阅读(241) | 评论(0) | 转发(0) |