Oracle分析函式(同比,環比,累計,基比)

2021-09-01 11:09:51 字數 1297 閱讀 5283

oracle分析函式(同比,環比,累計,基比)  分類:

oracle

create table salarybymonth

employeeno varchar2(20),

yearmonth varchar2(6),

salary number

) ;insert into salarybymonth (employeeno, yearmonth, salary)

values (1, '200805', 500);

insert into salarybymonth (employeeno, yearmonth, salary)

values (1, '200802', 150);

insert into salarybymonth (employeeno, yearmonth, salary)

values (1, '200803', 200);

insert into salarybymonth (employeeno, yearmonth, salary)

values (1, '200804', 300);

insert into salarybymonth (employeeno, yearmonth, salary)

values (1, '200708', 100);

commit;

select employeeno

,yearmonth

,salary

,min(salary) keep(dense_rank first order by yearmonth) over(partition by employeeno) first_salary -- 基比分析 salary/first_salary 

,lag(salary, 1, 0) over(partition by employeeno order by yearmonth) as prev_sal -- 環比分析,與上個月份進行比較 

,lag(salary, 12, 0) over(partition by employeeno order by yearmonth) as prev_12_sal -- 同比分析,與上個年度相同月份進行比較    

,sum(salary) over(partition by employeeno, substr(yearmonth, 1, 4) order by yearmonth range unbounded preceding) lj --累計值

from salarybymonth

order by employeeno

,yearmonth

Oracle同比 環比和累計

create table salarybymonth employeeno varchar2 20 yearmonth varchar2 6 salary number insert into salarybymonth employeeno,yearmonth,salary values 1,20...

視窗函式計算同比環比

環比,表示連續2個單位週期 比如連續兩月 內的量的變化比,反映本期比上期增長了多少 計算公式 環比增長率 本期數 上期數 上期數 100 例如某 2018年2月份銷售額比2018年1月份銷售額增長了多少。同比,今年第n月與去年第n月比,用以說明本期發展水平與去年同期發展水平對比而達到的相對發展速度,...

計算同比 環比 PowerBI中同比環比那點事

哈嘍,這裡是白茶。乙個powerbi的初學者,記得在剛開始學dax的時候,乙個同比環比的問題困擾了我很久,每次都是覺得自己剛剛理解一點東西了,但是發現後續的坑更多。話不多說,look!這是我自己做的示例檔案,準備測試工作。將資料匯入powerbi中。begin 下面就可以準備進行同比環比的測試了,白...