分期值累计值的相互转换

Posted linyuansun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分期值累计值的相互转换相关的知识,希望对你有一定的参考价值。


-- 分期值到累计值代码示例1
with temp00 as (
select
‘2020-01-01‘ date1,
1 num1
union all
select
‘2020-01-02‘ adate1,
2 num1
union all
select
‘2020-01-03‘ date1,
3 num1
union all
select
‘2020-01-04‘ date1,
4 num1 )

select
t1.date1 new_date,
sum(t2.num1) new_num
from
temp00 t1
inner join
temp00 t2
on t1.date1>=t2.date1
group by
t1.date1


-- 分期值到累计值代码示例2
with temp00 as (
-- temp00 要保证date1、class1非空、非null,不然没有意义
select
‘2020-01-01‘ date1,
1 num1,
‘aa‘ class1
union all
select
‘2020-01-02‘ date1,
2 num1,
‘aa‘ class1
union all
select
‘2020-01-03‘ date1,
3 num1,
‘aa‘ class1
union all
select
‘2020-01-04‘ date1,
4 num1,
‘aa‘ class1
union all
select
‘2020-01-01‘ date1,
1 num1,
‘bb‘ class1
union all
select
‘2020-01-02‘ date1,
2 num1,
‘bb‘ class1
union all
select
‘2020-01-03‘ date1,
3 num1,
‘bb‘ class1 )

select
t1.date1 new_date,
t1.class1 new_class,
sum(isnull(t2.num1,0)) new_num
from
temp00 t1
left join
temp00 t2
on t1.date1>=t2.date1
and t1.class1=t2.class1
group by
t1.date1,
t1.class1





-- 分期值到累计值代码示例1
with temp00 as (
select
‘2020-01-01‘ date1,
1 num1
union all
select
‘2020-01-02‘ date1,
3 num1
union all
select
‘2020-01-03‘ date1,
6 num1
union all
select
‘2020-01-04‘ date1,
10 num1 )

select
t1.date1 new_date,
max(isnull(t1.num1,0))-max(isnull(t2.num1,0)) new_num
from
temp00 t1
left join
temp00 t2
on t1.date1>t2.date1
group by
t1.date1


-- 分期值到累计值代码示例2
with temp00 as (
-- temp00 要保证date1、class1非空、非null,不然没有意义
select
‘2020-01-01‘ date1,
‘aa‘ class1,
1 num1
union all
select
‘2020-01-02‘ date1,
‘aa‘ class1,
3 num1
union all
select
‘2020-01-03‘ date1,
‘aa‘ class1,
 6 num1
union all
select
‘2020-01-04‘ date1,
‘aa‘ class1,
10 num1
union all
select
‘2020-01-01‘ date1,
‘bb‘ class1,
1 num1
union all
select
‘2020-01-02‘ date1,
‘bb‘ class1,
3 num1
union all
select
‘2020-01-03‘ date1,
‘bb‘ class1,
6 num1 )

select
t1.date1 new_date,
t1.class1 new_class,
max(isnull(t1.num1,0))-max(isnull(t2.num1,0)) new_num
from
temp00 t1
left join
temp00 t2
on t1.date1>t2.date1
and t1.class1=t2.class1
group by
t1.date1,
t1.class1

以上是关于分期值累计值的相互转换的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript随机生成颜色以及十六进制颜色 与RGB颜色值的相互转换

java线程的6种状态以及相互转换

Flutter模型与json的相互转换

Flutter模型与json的相互转换

Flutter模型与json的相互转换

java中的BigDecimal和String的相互转换