需求:要求安装月份查询结果展示每天和总合计的数据,如果在当前月份查询只展示当月当前今天的数据。
例如:当前是3月份查询构造时间如下:
select c stat_day,1 order_no from(
select '201703'||'01' c from dual union all select '201703'||'02' c from dual union all select '201703'||'03' c from dual union all
select '201703'||'04' c from dual union all select '201703'||'05' c from dual union all select '201703'||'06' c from dual union all
select '201703'||'07' c from dual union all select '201703'||'08' c from dual union all select '201703'||'09' c from dual union all
select '201703'||'10' c from dual union all select '201703'||'11' c from dual union all select '201703'||'12' c from dual union all
select '201703'||'13' c from dual union all select '201703'||'14' c from dual union all select '201703'||'15' c from dual union all
select '201703'||'16' c from dual union all select '201703'||'17' c from dual union all select '201703'||'18' c from dual union all
select '201703'||'19' c from dual union all select '201703'||'20' c from dual union all select '201703'||'21' c from dual union all
select '201703'||'22' c from dual union all select '201703'||'23' c from dual union all select '201703'||'24' c from dual union all
select '201703'||'25' c from dual union all select '201703'||'26' c from dual union all select '201703'||'27' c from dual union all
select '201703'||'28' c from dual union all select '201703'||'29' c from dual union all select '201703'||'30' c from dual union all
select '201703'||'31' c from dual)
where c<当前时间日期
and c<=to_char(last_day(to_date('201703','yyyymm')),'yyyymmdd')
union all
select '合计' stat_day,0 order_no from dual;
说明:使用小于当前时间筛选当月的日期、使用c<=to_char(last_day(to_date('201703','yyyymm')),'yyyymmdd')筛选已过月份的日期。
阅读(1885) | 评论(0) | 转发(0) |