根据查询日期计算每五天平均量,比如我查询一号至六号,就计算五号(1至5)平均量,六号(2至6)平均量; 注:默认查询一个月 SELECT A.* FROM ( SELECT to_char(dateTime , 'yyyy-mm-dd') KSRQ , to_char(dateTime+4, 'yyyy-mm-dd') JSRQ , TO_CHAR(dateTime,'WW') ZS FROM ( select (dateTime) dateTime,Rownum rn from (with t as (select rownum-1 rn from dual connect by rownum<=10000) select (to_date('2021-01-01','yyyy-mm-dd')+rn) as dateTime from t where to_date('2021-01-01','yyyy-mm-dd') + rn < to_date('2021-12-31','yyyy-mm-dd') ) b where --to_char(b.dateTime,'yyyy-mm-dd')>='2021-01-01' and to_char(b.dateTime,'yyyy-mm-dd')<='2021-01-05' to_char(b.dateTime, 'day') = '星期五' ) ) A 这是之前做的一个按照一周计算的sql,麻烦大神可以优化下这个SQL吗?按照每五天计算,谢谢 |