SKEWNESS_POP and SKEWNESS_SAMP Analytic Functions
The SKEWNESS_POP and SKEWNESS_SAMP analytic functions were added in Oracle 21c to measure asymmetry, or skew, in the distribution of data.
oracle 21cconfigurationintermediate
by OracleDba
13 views
The SKEWNESS_POP and SKEWNESS_SAMP analytic functions were added in Oracle 21c to measure asymmetry, or skew, in the distribution of data.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
-- drop table t1 purge;
create table t1 (
id number generated always as identity,
left_skew number,
normal number,
right_skew number
);
insert into t1 (left_skew, normal, right_skew)
select case
when level > 9800 then 1
else dbms_random.value(400, 500)
end,
dbms_random.normal,
case
when level < 200 then dbms_random.value(400, 500)
else 1
end
from dual
connect by level <= 10000;
commit;
create table emp (
empno number(4) constraint pk_emp primary key,
ename varchar2(10),
job varchar2(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2) );
insert into emp values (7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
insert into emp values (7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
insert into emp values (7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
insert into emp values (7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
insert into emp values (7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
insert into emp values (7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
insert into emp values (7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
insert into emp values (7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87','dd-mm-rr')-85,3000,NULL,20);
insert into emp values (7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
insert into emp values (7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
insert into emp values (7876,'ADAMS','CLERK',7788,to_date('13-JUL-87', 'dd-mm-rr')-51,1100,NULL,20);
insert into emp values (7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
insert into emp values (7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
insert into emp values (7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
commit;123456789101112131415161718192021222324252627282930313233
select skewness_pop(left_skew) as left_skew,
skewness_pop(normal) as normal,
skewness_pop(right_skew) as right_skew
from t1;
LEFT_SKEW NORMAL RIGHT_SKEW
---------- ---------- ----------
-5.1049315 -.0077114 6.91847714
SQL>
select skewness_samp(left_skew) as left_skew,
skewness_samp(normal) as normal,
skewness_samp(right_skew) as right_skew
from t1;
LEFT_SKEW NORMAL RIGHT_SKEW
---------- ---------- ----------
-5.1056973 -.00771256 6.91951511
SQL>
select skewness_samp(distinct left_skew) as skew_distinct,
skewness_samp(unique left_skew) as skew_unique,
skewness_samp(all left_skew) as skew_all,
skewness_samp(left_skew) as skew
from t1;
SKEW_DISTINCT SKEW_UNIQUE SKEW_ALL SKEW
------------- ----------- ---------- ----------
-0.370901916 -0.370901916 -5.11615858 -5.11615858
SQL>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
select empno,
ename,
deptno,
sal,
round(skewness_pop(sal) over (),2) as sal_skew
from emp;
EMPNO ENAME DEPTNO SAL SAL_SKEW
---------- ---------- ---------- ---------- ----------
7369 SMITH 20 800 1.04
7499 ALLEN 30 1600 1.04
7521 WARD 30 1250 1.04
7566 JONES 20 2975 1.04
7654 MARTIN 30 1250 1.04
7698 BLAKE 30 2850 1.04
7782 CLARK 10 2450 1.04
7788 SCOTT 20 3000 1.04
7839 KING 10 5000 1.04
7844 TURNER 30 1500 1.04
7876 ADAMS 20 1100 1.04
7900 JAMES 30 950 1.04
7902 FORD 20 3000 1.04
7934 MILLER 10 1300 1.04
SQL>
select empno,
ename,
deptno,
sal,
round(skewness_pop(sal) over (partition by deptno),2) as sal_skew_by_dept
from emp;
EMPNO ENAME DEPTNO SAL SAL_SKEW_BY_DEPT
---------- ---------- ---------- ---------- ----------------
7782 CLARK 10 2450 .43
7839 KING 10 5000 .43
7934 MILLER 10 1300 .43
7566 JONES 20 2975 -0.44
7902 FORD 20 3000 -0.44
7876 ADAMS 20 1100 -0.44
7369 SMITH 20 800 -0.44
7788 SCOTT 20 3000 -0.44
7521 WARD 30 1250 1.33
7844 TURNER 30 1500 1.33
7499 ALLEN 30 1600 1.33
7900 JAMES 30 950 1.33
7698 BLAKE 30 2850 1.33
7654 MARTIN 30 1250 1.33
SQL>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
select empno,
ename,
deptno,
sal,
round(skewness_samp(sal) over (),2) as sal_skew
from emp;
EMPNO ENAME DEPTNO SAL SAL_SKEW
---------- ---------- ---------- ---------- ----------
7369 SMITH 20 800 1.17
7499 ALLEN 30 1600 1.17
7521 WARD 30 1250 1.17
7566 JONES 20 2975 1.17
7654 MARTIN 30 1250 1.17
7698 BLAKE 30 2850 1.17
7782 CLARK 10 2450 1.17
7788 SCOTT 20 3000 1.17
7839 KING 10 5000 1.17
7844 TURNER 30 1500 1.17
7876 ADAMS 20 1100 1.17
7900 JAMES 30 950 1.17
7902 FORD 20 3000 1.17
7934 MILLER 10 1300 1.17
SQL>
select empno,
ename,
deptno,
sal,
round(skewness_samp(sal) over (partition by deptno),2) as sal_skew_by_dept
from emp;
EMPNO ENAME DEPTNO SAL SAL_SKEW_BY_DEPT
---------- ---------- ---------- ---------- ----------------
7782 CLARK 10 2450 1.04
7839 KING 10 5000 1.04
7934 MILLER 10 1300 1.04
7566 JONES 20 2975 -0.65
7902 FORD 20 3000 -0.65
7876 ADAMS 20 1100 -0.65
7369 SMITH 20 800 -0.65
7788 SCOTT 20 3000 -0.65
7521 WARD 30 1250 1.82
7844 TURNER 30 1500 1.82
7499 ALLEN 30 1600 1.82
7900 JAMES 30 950 1.82
7698 BLAKE 30 2850 1.82
7654 MARTIN 30 1250 1.82
SQL>Please to add comments
No comments yet. Be the first to comment!