Oracle 、SqlServer 根据日期逐日、逐月递增累加、逐行累加

前端之家收集整理的这篇文章主要介绍了Oracle 、SqlServer 根据日期逐日、逐月递增累加、逐行累加前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

动态追加日累计、月累计:

  1. 测试表tb_test_over 中有SCRQ、RSJ两列,存储每日的日数据;
select * from tb_test_over ;
  1. 使用OVER函数动态追加列,根据SCRQRSJ累计求和;
select scrq,rsj,sum(rsj) over(order by scrq) as nsj from tb_test_over order by scrq;
  1. 使用OVER 结合 PARTITION BY 对每月进行累加;
select scrq,sum(rsj) over(partition by to_char(scrq,'yyyy-mm') order by scrq) ysj from tb_test_over order by scrq;
  1. 综合版,查询日、月、年累加数据;
select scrq,'yyyy-mm') order by scrq) ysj,sum(rsj) over(order by scrq) as nsj from tb_test_over order by scrq;

5、最后追加一个动态字符列转行技巧;
'A,B,V,C,D,S,A'这么一个字符串,根据逗号将数据输出到每行;

SELECT REGEXP_SUBSTR ('A,A','[^,]+',1,ROWNUM) as str FROM DUAL CONNECT BY ROWNUM <= LENGTH ('A,A') - LENGTH (REPLACE ('A,',',''))+1;
原文链接:https://www.f2er.com/oracle/206033.html

猜你在找的Oracle相关文章